A suggestion for a possible Python module

Jp Calderone exarkun at intarweb.us
Wed Mar 5 11:17:23 EST 2003


On Wed, Mar 05, 2003 at 11:07:42AM -0500, Terry Reedy wrote:
> 
> "Jp Calderone" <exarkun at intarweb.us> wrote in message
> news:mailman.1046876115.32389.python-list at python.org...
> > On Wed, Mar 05, 2003 at 12:24:10AM -0500, Terry Reedy wrote:
> > > s.reverse([i[,j]])     reverses the items of s[i:j] in place
> within s (6) (10)
> > > <and add, subject to footnote renumbering>
> > > 10
> > >        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.
> 
> >   Do you plan to support negative indices?
> 
> Good question.  For myself, yes:  I want that s.reverse(i,j) be
> semantically equal to
> 
> tem = s[i:j]
> tem.reverse()
> s[i:j] = tem
> 
> No new rules to learn.
> 
> I considered the possibility of a third (step) param, but rejected
> such so far because a) I don't know if s[i:j:k] = whatever is legal
> and b) I have not been able to think of any real use case, let alone
> one that would justify the added complexity.


  For the first part,

    s[i:j:k] = whatever

  is the same as

    s.__setitem__(slice(i, j, k), whatever)

  so it's legal, syntatically, but only works if the invoked __setitem__
implementation actually implements it sensibly.

  I can't think of any real use cases for it either, though.

  Jp

--
 up 2 days, 7:58, 5 users, load average: 0.03, 0.01, 0.00





More information about the Python-list mailing list