[Python-Dev] Re: PEP 322: Reverse Iteration (original) (raw)

Alex Martelli aleaxit at yahoo.com
Wed Nov 5 10:56:21 EST 2003


On Wednesday 05 November 2003 04:02 pm, Guido van Rossum wrote:

> Among the comp.lang.python crowd, nearly everyone supported some form of > the PEP (with varying preferences on the name or where to put it). The > community participation rate was high with about 120 posts across four > threads contributing to hammering out the current version of the pep.

How many participants in those 120 posts? (I recall a thread where one individual posted 100 messages. :-)

I count 25 separate contributors to threads about PEP 322 (but I only see 75 posts there, and three threads, so I must be missing some of those that Raymond is counting -- or perhaps, not unlikely, they've expired off my newsserver).

> Is there anything else that needs to be done in the way of research, > voting, or cheerleading for pep to be accepted?

Yes. I'm getting cold feet about reversed. Some folks seem to think that reversed() can be made to work on many iterators by having the iterator supply reversed; I think this is asking for trouble (e.g. you already pointed out why it couldn't be done for enumerate()).

I still think it could be, if enumerate kept a reference to its argument, but that's a detail -- I trust your instinct about such design issues (or I wouldn't be using Python...:-). So: let's keep it simple and have reversed be exactly equivalent to (net of performance, hypothetical anomalous "pseudosequences" doing weird things, & exact error kinds/msgs):

def reversed(sequence): for x in xrange(len(sequence)-1, -1, -1): yield sequence[x]

no reversed, no complications, "no nuttin'".

Putting that in the current 2.4 pre-alpha will let us start getting some experience with it and see if in the future we want to add refinements (always easier to add than to remove...:-) -- either to reverse or to other iterator-returning calls (e.g. reverse= optional arguments just like in the sort method of lists).

Alex



More information about the Python-Dev mailing list