iterating in reverse
Andrew Bennetts
andrew-pythonlist at puzzling.org
Fri Jan 17 04:16:49 EST 2003
On Fri, Jan 17, 2003 at 12:45:48AM -0800, Paul Rubin wrote:
> 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.
It probably does -- but I don't know, and therefore it's good enough <wink>.
what-I-don't-know-can't-hurt-me-'ly yrs, Andrew.
More information about the Python-list
mailing list