Send As SMS

8/4/2006

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

My blog has moved! Redirecting...

You should be automatically redirected. If not, visit http://stinkpot.afraid.org:8080/tricks/ and update your bookmarks.