PEP 322: Reverse Iteration (second revision, please comment)

Werner Schiendl ws-news at gmx.at
Thu Oct 30 05:38:42 EST 2003


Raymond Hettinger wrote:

> * reversed() is being preferred to ireverse() as the best name.
> 

+1

even though "reverse" as a verb would be more consistent with "zip" and 
"enumerate", it could be assumed to change the sequence passed as arg 
(it sounds like a command)

So I agree that "reversed" is the best alternative IMHO

> 
> Also, please take a look at the revrange() alternative to see if you
> prefer it or not.

Personally I think it's easier to write xrange(len(seq)-1,-1,-1) than
to remember one more function name for something that trivial.

In addition, there are rare cases where I did ever need the index.
And in that cases, enumerate is mostly what i *really* wanted.

I cannot remember to ever having had a need for reverse enumerate...

It IMHO much more beatiful to say:

for item in seq:
     print item

than:

for i in xrange(len(seq)):
     print seq[i]

because the former communicates the intent (do something for all items 
in the sequence).

This is one of the things I really miss when doing work in e. g. C


I'm -0 on revrange in general and -1 as a replacement for "reversed".

To me it rather adds complexity than helps...


best regards

Werner





More information about the Python-list mailing list