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

Raymond Hettinger python at rcn.com
Tue Nov 4 19:49:06 EST 2003


> > I believe the assumption is that enumerate (as well as the proposed
> irange)
> > would grow an __reversed__ method to handle just that usage.

Unfortunately, that idea didn't work out.  The enumerate object does not
hold the original iterable; instead, it only has the result of
iter(iterable).  Without having the iterable, I don't see a way for it
to call iterable.__reversed__.  The essential problem that at creation
time, the enumerate object does know that it is going to be called by
reversed().

No other sequence object has to have a __reversed__ method.  Like its
cousin, __iter__, some objects may be a performance boost from a custom
iterator but none of them have to have it.


Raymond Hettinger




More information about the Python-Dev mailing list