Comment on PEP-0322: Reverse Iteration Methods

Sean Ross sross at connectmail.carleton.ca
Fri Sep 26 11:20:41 EDT 2003


"David Abrahams" <dave at boost-consulting.com> wrote in message
news:uk77vhagj.fsf at boost-consulting.com...
[snip]
> FWIW, burdening builtins aside I consider the proposed syntax
>
>       for i in xrange(n).iter_backwards():
>
> much uglier than
>
>      for i in reverse_view(xrange(n)):
>
> but far superior to
>
>      for i in reverse(xrange(n)):
>
> which implies in-place modification of the sequence.

How about

from itertools import ireverse
for i in ireverse(xrange(n)):
    # suite

ireverse(), like imap(), izip(), etc., suggests that the operation is
iterative, and that no modification of the original sequence will be
performed. Others have suggested riter() (right iteration), in order to form
an association with the iter() builtin. As a matter of taste, I prefer
ireverse().

Sean






More information about the Python-list mailing list