>>> list = [1,2,3]
>>> reversed(list) # => <listreverseiterator object>
>>> list.reverse() # =>Destructive operation
>>> list
[3,2,1]
>>> list = [1,2,3]
>>> list[::-1] # =>The simplest and most powerful
[3,2,1]
>>> list = [1,2,3]
>>> def inc(n):
... return n+1
...
>>> #Redundant but easy to understand
>>> for i in reversed(list):
... print inc(i)
...
4
3
2
>>> #Be careful because it is a destructive operation
>>> list.reverse()
>>> for i in list:
... print inc(i)
...
4
3
2
>>> list = [1,2,3]
>>> map(inc, list[::-1]) # =>Concise and powerful
[4, 3, 2]
Recommended Posts