PEP 322: Reverse Iteration (REVISED, please comment)

John Roth newsgroups at jhrothjr.com
Tue Oct 28 18:38:39 EST 2003


+1


"Raymond Hettinger" <python at rcn.com> wrote in message
news:5d83790c.0310281022.6264aa16 at posting.google.com...
> Based on your extensive feedback, PEP 322 has been completely revised.
> The response was strongly positive, but almost everyone preferred
> having a function instead of multiple object methods.  The updated
> proposal is at:
>
>     www.python.org/peps/pep-0322.html
>
> In a nutshell, it proposes a builtin function that greatly simplifies
reverse
> iteration.  The core concept is that clarity comes from specifying a
> sequence in a forward direction and then saying, "inreverse()":
>
>     for elem in inreverse(seqn):
>          . . .
>
> Unlike seqn[::-1], this produces a fast iterator instead of a full
reversed
> copy.
>
> Discussions with Guido made it clear that inreverse() will not be extended
> to cover all iterables.  The proposal is about simplicity, expression, and
> performance.  As such, it would be counter-productive to take in a general
> iterable, run it to completion, save the data in memory, and then iterate
> over the data in reverse.

It's certainly clear enough, and I like it in general.

I'd appreciate a bit of discussion about why reverse() was rejected as
the name, though.

John Roth
>
>
> Raymond Hettinger






More information about the Python-list mailing list