[Python-Dev] PEP 322: Reverse Iteration

Guido van Rossum guido at python.org
Tue Nov 4 19:07:40 EST 2003


> > >     for i, value in reversed(enumerate(listofnum)):
> >
> > Sorry, this doesn't work.  enumerate() returns an iterator, reversed()
> > requires a sequence.
> 
> I believe the assumption is that enumerate (as well as the proposed irange) 
> would grow an __reversed__ method to handle just that usage.

Ah, so it is.  Then the PEP's abstract is wrong:

"""
This proposal is to add a builtin function to support reverse
iteration over sequences.
"""

Also, the PEP should enumerate (:-) which built-in types should be
modified in this way, to give an impression of the enormity (or not)
of the task.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list