read a list backwards in python
to iterate over a list in reverse order in python, i use the 'reverse' method. i'm sure there are faster ways to do this in terms of running time, but its hard to conceive of anything easier to implement.
here goes: to iterate over 'my_list' backwards, write:
my_list.reverse()
for item in my_list:
print item
0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home