A suggestion for a possible Python module

Terry Reedy tjreedy at udel.edu
Wed Mar 5 06:24:10 CET 2003

"Alex Martelli" <aleax at aleax.it> wrote in message
news:kO49a.5064$zo2.155460 at news2.tin.it...
> Terry Reedy wrote:
>   ...
> > Does something as small as this need a PEP or would a feature
> > (aliased as bug report) or patch (obviously better, but I can't
> > one yet) be more appropriate?
> A PEP _accompanied_ by a patch would be ideal.  (I'll volunteer to
> do the code patch, and co-author the PEP, if you'll be "lead author"
> and write the patch for the docs and the tests... deal?)

Yes -- if we agree on details -- and you make diffs from plaintext
'patches' if/when needed.  For a start:

Lib Ref Mutable Sequence Types

s.reverse()        reverses the items of s in place        (6)
s.reverse([i[,j]])     reverses the items of s[i:j] in place within s
(6) (10)
<and add, subject to footnote renumbering>
       The optional arguments i and j act like slice bounds and
default to 0 and len(s).  The default with no arguments reverses the
entire sequence.

Lib Ref 5.10 array -- Efficient arrays of numeric values

reverse( )
     Reverse the order of the items in the array.
     Reverse the order of the items, in place, in array[i:j].   The
optional arguments i and j default to 0 and len(array), so the
no-argument default is to reverse the entire array.

Possible PEP Issue

Q. Should this PEP be extended to addition of a string.reverse method.

A. No.  In-place reversal is not possible, and extract and reverse is
already possible: string[::-1] extracts reversed copy of string;
string[i:j][::-1] extracts slice and then reverses it into a second
copy; for the rare case where this is both needed and needs to be
efficient, string[j-1:i-1:-1] will extract and reverse in one step


More information about the Python-list mailing list