Pre-PEP: reverse iteration methods

Hannu Kankaanpää hanzspam at yahoo.com.au
Wed Sep 24 06:38:11 EDT 2003


Stephen Horne <$$$$$$$$$$$$$$$$$@$$$$$$$$$$$$$$$$$$$$.co.uk> wrote in message news:<f4b2nv8vs81v6egonckq7935jmh6a8gku6 at 4ax.com>...
> >* Should enumerate() be included?  It would only provide reverse iteration
> >  whenever the underlying sequence supported it.
> 
> Why not...
> 
>   for i, j in enumerate (listname.iter_backwards ()) :
> 
> in other words, as enumerate can handle the already-reversed
> sequence/iteration, I don't see the point.

That's not the same:

>>> list(enumerate([10,11,12]))
[(0, 10), (1, 11), (2, 12)]
>>> list(enumerate([10,11,12].riter()))
[(0, 12), (1, 11), (2, 10)]
>>> list(enumerate([10,11,12]).riter())
[(2, 12), (1, 11), (0, 10)]

Indices would also be reversed.




More information about the Python-list mailing list