iterating in reverse
phr-n2002b at NOSPAMnightsong.com
Fri Jan 17 09:45:48 CET 2003
Andrew Bennetts <andrew-pythonlist at puzzling.org> writes:
> > will always print x's contents in the
> > same sequence. Is there an elegant and
> > efficient way to iterate through x in
> > reverse without having to create a reversed
> > copy of it (i.e. y=x[:]; y.reverse())?
> Get the Python 2.3 alpha, and it's really easy :)
> >>> l = [1,2,3,4,5]
> >>> for i in l[::-1]:
> ... print i
My guess is that the above creates a reversed copy.
More information about the Python-list