PEP 322: Reverse Iteration (REVISED, please comment)

Paul Moore pf_moore at yahoo.co.uk
Tue Oct 28 16:30:22 EST 2003


python at rcn.com (Raymond Hettinger) writes:

> 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):
>          . . .

I've got to say, I really don't like the name. Particularly, the
repeated "in" in "in inreverse..." strikes me as ugly.

> 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.

I like the proposal, it's simple and expressive. But please, change
the name! I assume there's a good reason why the obvious "reverse()"
wasn't chosen. Of the alternatives in the PEP, backwards() doesn't
seem to read nicely (but it's better than inreverse!!!), and ireverse
is OK, but makes me think that it should be in itertools (or all the
itertools should be builtin). Some other possibilities:

    rev(seq) - probably too abbreviated
    reversed(seq) - adjective rather than verb, but reads well

As usual, the semantics is perfectly acceptable, but we'll have a nice
long argument over the name :-)

Paul.
-- 
This signature intentionally left blank




More information about the Python-list mailing list