On 27/10/2013 17:04, Guido van Rossum wrote:For a positive stride, omitting the second bound is equivalent to
In the comments of
http://python-history.blogspot.com/2013/10/why-python-uses-0-based-indexing.html
there were some complaints about the interpretation of the bounds for
negative strides, and I have to admin it feels wrong. Where did we go
wrong? For example,
"abcde"[::-1] == "edcba"
as you'd expect, but there is no number you can put as the second bound
to get the same result:
"abcde"[:1:-1] == "edc"
"abcde"[:0:-1] == "edcb"
but
"abcde":-1:-1] == ""
I'm guessing it all comes from the semantics I assigned to negative
stride for range() long ago, unthinkingly combined with the rules for
negative indices.
length + 1:
>>> "abcde"[:6:1]
'abcde'
For a negative stride, omitting the second bound is equivalent to
-(length + 1):
>>> "abcde"[:-6:-1]
'edcba'