網頁

2016年10月18日 星期二

How can I reverse a list in python?

This syntax works for any interable, not just lists. It just returns a new reversed list, but it doesn't modify the original one.
L=[01020, 40]
L[::-1]
[40, 20, 10, 0]
The syntax represanted as [start:stop:step], so step is -1. You're only returning the values in reverse 

To actually reverse the list,