[issue11842] slice.indices with negative step and default stop

João Sebastião de Oliveira Bueno report at bugs.python.org
Thu Apr 14 01:41:07 CEST 2011


João Sebastião de Oliveira Bueno <gwidion at gmail.com> added the comment:

I don't see this as a bug. The indices returned in both cases are exactly what you need to feed to range, in order to get the correct indices for the provided slice parameters.

Perceive that if for 
s = slice(None, None, -2)

It would return anything different from
(9, -1, -2)
It would be impossible to properly generate the desired indices. (With a 0 instead of -1, we would be missing the last index).

When you pass these numbers with the "[" "]" notation for being used as indices, the negative index is interpreted as "len(sequence) - index". In the case of "-1" in your example it is the same as "9" not the same as "one before zero".

I recommend closing this as not a bug.

----------
nosy: +João.Sebastião.de.Oliveira.Bueno

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11842>
_______________________________________


More information about the Python-bugs-list mailing list