Comment on PEP-0322: Reverse Iteration Methods

Stephen Horne $$$$$$$$$$$$$$$$$ at $$$$$$$$$$$$$$$$$$$$.co.uk
Thu Sep 25 19:05:23 EDT 2003


On Thu, 25 Sep 2003 00:58:45 GMT, "Raymond Hettinger"
<vze4rx4y at verizon.net> wrote:

>Please comment on the new PEP for reverse iteration methods.

One more thought.

Having an iter_backwards method on xrange seems wrong. This suggests
multiple functions/methods...

  To generate backward ranges
    range_backwards function
    xrange_backwards funtion

    for i in range_backwards (10) :
      ...

  To iterate an object backwards
    either method for appropriate objects, or
    iter_backward() function and __iter_backward__ magic method
    (I don't mind abbreviating the 'iter', but I think the 'backward'
    needs to be kept very obvious and not reduced to an easily missed
    'r' prefix).

    for i in iter_backwards (seq) :
      ...

  To enumate backwards etc
    Add an enumerate_backward function which requires the input to
    support __len__.

    for i in enumerate_backwards (seq) :
      ...

  For backward slicing
    Add a function which translates the slice to a backward equivalent
    before applying it...

    for i in slice_backwards (seq, start, stop, step) :
      ...


-- 
Steve Horne

steve at ninereeds dot fsnet dot co dot uk




More information about the Python-list mailing list