[Python-ideas] Where did we go wrong with negative stride?
Oscar Benjamin
oscar.j.benjamin at gmail.com
Sun Oct 27 20:05:54 CET 2013
On 27 October 2013 18:32, Guido van Rossum <guido at python.org> wrote:
>
> Hm, so the idea is that with a negative stride you you should use negative
> indices.
The same problem arises when using a negative indices and a positive
stride e.g.:
# Chop off last n elements
x_chopped = x[:-n] # Fails when n == 0
The solution is to use a positive end condition:
x_chopped = x[:len(x)+1-n]
Oscar
More information about the Python-ideas
mailing list