[Python-ideas] Where did we go wrong with negative stride?

Serhiy Storchaka storchaka at gmail.com
Mon Oct 28 15:11:13 CET 2013


28.10.13 08:33, Chris Angelico написав(ла):
> If it'd help, you could borrow Pike's syntax for counting-from-end
> ranges: <2 means 2 from the end, <0 means 0 from the end. So
> "abcdefg"[:<2] would be "abcde", and "abcdefg"[:<0] would be
> "abcdefg". Currently that's invalid syntax (putting a binary operator
> with no preceding operand), so it'd be safe and unambiguous.

There are parallels with alignment. C-style formatting uses positive 
width for right-aligned formatting and negative width for right-aligned 
formatting. New-style formatting uses positive '>' for right-aligned 
formatting and '<' for left-aligned formatting.

So '>' should indicate counting from begin (as positive index now) and 
'<' should indicate counting from end (as negative index now). And '^' 
should indicate counting from center.




More information about the Python-ideas mailing list