Extended slices and indices

GavinCrooks at gmail.com GavinCrooks at gmail.com
Sat Sep 23 21:48:14 EDT 2006


Robert Kern wrote:
> I'd say bug in the .indices() method. The meaning of [4:-1:-1] is unavoidable
> different than [::-1] since the index -1 points to the last element, not the
> imaginary element before the first element. Unfortunately, there *is* no
> concrete (start, stop, step) tuple that will emulate [::-1].

After some more experimenting, it seems that [L-1:-L-1:-1] will reverse
a sequence of length L. But slice(L-1,-L-1,-1).indices(L) gives (L-1,
-1,-1) which will not reverse the sequence. And range(L-1, -L-1, -1) is
totally off, but range(L-1,-1,-1) is correct.

Seems like a bug (or an odd feature) of extended slicing of strings and
other built in sequences.

GEC




More information about the Python-list mailing list