[newbie] Iterating a list in reverse ?

Tim Chase python.list at tim.thechases.com
Wed Jun 21 19:09:18 CEST 2006

> Python newbie:  I've got this simple task working (in about ten
> different ways), but I'm looking for the "favoured" and "most Python
> like" way.
> Forwards I can do this
> for t in listOfThings:
>     print t
> Now how do I do it in reverse?   

Then general process would be to use the reversed() iterator:

for t in reversed(listOfThings):
	print t

Python provides a sorted() wrapper of the same non-in-place form.


More information about the Python-list mailing list