[Python-ideas] Where did we go wrong with negative stride?
Ron Adam
ron3200 at gmail.com
Tue Oct 29 00:51:56 CET 2013
On 10/28/2013 04:31 PM, Tim Peters wrote:
> That's not what the proposal said, but it's a reasonable alternative.
> Maybe that's better because it's "more compatible" with what happens
> today. The hangup for me is that I have no use cases for negative
> strides other than -1, so have no real basis for picking one over the
> other. OTOH, since I_don't_ have any use cases, I don't care either
> what happens then;-)
>
>> >s[i:j:-k] == s[i:j:-1][::k]
> That's a nice form of symmetry too. Sold;-)
+1 Looks good to me.
We could add a new_slice object without any problems now. You just need to
be explicit when using it.
(This works now)
>>> "abcdefg"[slice(1,5,1)]
'bcde'
And this could work and not cause any compatibility issues.
"abcdefg"[new_slice(1, 5, -2)]
"ec"
It would offer an alternative for those who need or want it now and help
with the change over when/if the time comes.
We also need to remember that slicing is also used for inserting things.
>>> a = list("python")
>>> b = list("PYTHON")
>>> a[::2] = b[::2]
>>> a
['P', 'y', 'T', 'h', 'O', 'n']
Cheers,
Ron
More information about the Python-ideas
mailing list