PEP 322: Reverse Iteration (REVISED, please comment)

Raymond Hettinger vze4rx4y at verizon.net
Wed Oct 29 11:43:51 EST 2003


> The static method approach would clearly document that the
> result is an iterator (which none of the other names proposed
> really does IMHO)

Better name are welcome!

Moving it somewhere else is not open.  It is proposed as a builtin for a
reason -- it is a core looping tool like zip() or enumerate() and it is meant
to simplify rather than complicate code.

Static methods, class methods, and weird descriptors be darned, this is
not an exercise in how weirdly it can be implemented just to avoid
having a builtin.

Would everything be somehow better if Alex's wonderful sum() had
been implemented as a int.sum() classmethod or was tucked way in
another module?  Of course not!  Likewise, would zip() or enumerate()
be successful solutions to lock-step iteration and the loop-counter
problems if they were iter.zip() and iter.enumerate()?  No, of course not.
Let's put an end to this silliness right now.  The idea is offered as a
builtin or not at all; otherwise, the existing [::-1] starts to look better.


> In general, I'm +1 on the PEP

Thanks!  I certain it will make code more readable and reviewable.

The challenge with a PEP this simple is that experts feel this
overpowering urge to apply all their know-how and transform
in to something other than a clean, fast, simple solution.


Raymond Hettinger






More information about the Python-list mailing list