Slice objects with negative increment

Paul Hughett hughett at mercur.uphs.upenn.edu
Fri May 3 10:19:48 EDT 2002


Alex Martelli <aleax at aleax.it> wrote:

: Isn't that the whole point of "negative indices alias to nonnegative
: ones"?  It means that, for L>x>=0, x-L and x index the same item.

It's obvious in retrospect, but my mental model was that -n maps to
L-n, which doesn't immediately suggest that n and n-L are the same.
It probably didn't help that I learned slicing from Matlab, which does
not have the negative index convention.

: Explaining is surely good.  I think slicing can usefully be introduced
: before slice-objects -- the latter are a tad harder because more general,
: as they exist without specifically being tied to a given sequence (and
: thus in particular to a given sequence _length_, which influences the
: negative/nonnegative mapping).

Yes.  Thanks for explaining this issue for me.


Paul Hughett



More information about the Python-list mailing list