iterating in reverse

Jonathan P. jbperez808 at
Fri Jan 17 09:54:04 CET 2003

Chad Netzer <cnetzer at> wrote in message news:<mailman.1042765110.10945.python-list at>...

> FWIW. list.reverse() is often not too bad since it only has to do the 
> work of reversing the list indices in memory, not copying the actual 
> objects themselves.  Iterating backwards does save an O(N) operation, 
> but for small lists, list.reverse() is likely faster.

I need to iterate using for in both the original order and 
in reverse depending on the situation.

The main thing that bugs me is that I have to choose between 
storing 2 copies of the same data (one reversed, the other not)
or I have to do a couple of reverse()s each time (to undo the 
transformation) I need to access the list in reverse.  The former
is wasteful of space, the latter of performance.

More information about the Python-list mailing list