[Python-ideas] Where did we go wrong with negative stride?
Bruce Leban
bruce at leapyear.org
Mon Oct 28 04:00:23 CET 2013
On Sun, Oct 27, 2013 at 4:45 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>wrote:
> I think the only way to really fix this cleanly is to have
> a different *syntax* for counting from the end, rather than
> trying to guess from the value of the argument.
>
I was thinking the exact same thing today. Suppose the slice syntax was
changed to:
[start:stop:stride:reverse]
where 0 or None or False for reverse leaves the slice in order while any
True value reverses it. This would replace
'abcde'[2:5] == 'bcd'
'abcde'[2:5::True] == 'dcb'
'abcde'[::-2] == 'abcde'[::2:True] == 'eca'
'abcdef'[::-2] == 'fdb'
'abcdef'[::2:True] == 'eca'
As the last three examples, illustrate, sometimes the reverse is equivalent
to a negative stride and sometimes it's not.
--- Bruce
I'm hiring: http://www.cadencemd.com/info/jobs
Latest blog post: Alice's Puzzle Page http://www.vroospeak.com
Learn how hackers think: http://j.mp/gruyere-security
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131027/e284267c/attachment.html>
More information about the Python-ideas
mailing list