[Python-ideas] Where did we go wrong with negative stride?
Tim Peters
tim.peters at gmail.com
Tue Oct 29 01:41:37 CET 2013
[Ron Adam]
>> 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']
[Andrew Barnert]
> I was about to write the same thing. Half the mails so far have said things like "you don't
> need to do [i: j:k] because you can do [m:n:o][::p]".
You must be missing most of the messages, then ;-)
> But that doesn't work with assignment; you're just assigning to the temporary copy
> of the first slice.
> ...
Do you have a specific example of a currently-working slice assignment
that couldn't easily be done under proposed alternatives? I can't
think of one, under "my" proposal as amended by Terry. Ron's example
is no problem under any of them (because no proposal so far has
suggested changing the current meaning of [::2]).
When you see things like
s[i:j;k] = s[i:j][::k]
*nobody* is suggesting using the spelling on the RHS. They're
pointing out a pleasant mathematical equivalence.
More information about the Python-ideas
mailing list