PEP 322: Reverse Iteration (second revision, please comment)

From: Raymond Hettinger (vze4rx4y_at_verizon.net)
Date: 10/30/03


Date: Thu, 30 Oct 2003 08:00:08 GMT

Based on the feedback here on comp.lang.python, the pep has been
updated:

    www.python.org/peps/pep-0322.html

The key changes are:

* reversed() is being preferred to ireverse() as the best name.

* the sample implementation now clearly shows a check for a custom
  reverse method and a guard against being applied to a mapping.

* added sample output for enumerate.__reversed__ to show
  how a custom reverse method would work

* explained why the function is proposed as a builtin and why attachment
   to another module or type object is not being considered further.

* expanded comments on the real world use cases to show what the
   replacement code would look like.

Please continue to contribute your thoughts. I'm especially interested
in people examining their own code to verify that the new function
adds clarity and improves performance.

Also, please take a look at the revrange() alternative to see if you
prefer it or not.

Raymond Hettinger



Relevant Pages

  • Re: PEP 322: Reverse Iteration (second revision, please comment)
    ... Heh, I actually prefered ireverse. ... > reverse method and a guard against being applied to a mapping. ... > replacement code would look like. ...
    (comp.lang.python)
  • Re: PEP 322: Reverse Iteration (second revision, please comment)
    ... The explanation of why reverse() is not an option helps, ... > reverse method and a guard against being applied to a mapping. ... implementation would fail on a mapping, with a KeyError at the yield? ... Are you proposing to add such a custom reverse method to enumerate? ...
    (comp.lang.python)
  • Re: Where is string.Reverse() and string.SwapChars()?
    ... Why not add a Reverse method? ... converting it back to a string requires additional memory allocations, ... Reverse is the method of Array class, thus u can convert string to array ...
    (microsoft.public.dotnet.languages.csharp)
  • reverse a collection
    ... Array has a reverse method. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: python without OO
    ... if in Python the algorithm for the reverse function ... > whereas a reverse method would have to provided for each class that ... this is why Python not only provides the list.reversemethod to ...
    (comp.lang.python)