[Python-Dev] Re: PEP 322: Reverse Iteration

Phillip J. Eby pje at telecommunity.com
Wed Nov 5 09:54:43 EST 2003

At 07:29 AM 11/5/03 -0500, Raymond Hettinger wrote:
>Not really.  When you go to write the code, it becomes clear that it
>doesn't apply to enumerate or the other itertools.  The issue is that
>the iterator object holds only the result of iter(iterable) and is in no
>position to re-probe the underlying iterable to see if it supports
>reverse iteration.  The iterator object has no way of knowing in advance
>that it is going to be called by reversed().

Why not change enumerate() to return an iterable, rather than an 
iterator?  Then its __reversed__ method could attempt to delegate to the 
underlying iterable.  Is it likely that anyone relies on enumerate() being 
an iterator, rather than an iterable?

More information about the Python-Dev mailing list