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

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Oct 28 22:29:35 CET 2013


Barry Warsaw wrote:
> On Oct 28, 2013, at 11:00 PM, Nick Coghlan wrote:
> 
>>"[<i:" closed start of slice (default)
>>"[i<:" open start of slice
>>":>j]" open end of slice (default)
>>":j>]" closed end of slice
>>":>j:k]" open end of slice with step
>>":j>:k]" closed end of slice with step
>
> Sorry, I'm -1 here.  ...  I don't think this syntax will make it easier to
> understand at a glance (or even upon some deeper inspection).

I agree that this looks far too cluttered.

Joshua's ~ idea shows that we don't need separate syntax for
"from the start" and "from the end", just something that means
"from the other end". Also we want a character that doesn't
look too obtrusive and doesn't already have a meaning the
way we're using it. How about:

    a[^i:j]
    a[i:^j]
    a[^i:^j]

-- 
Greg


More information about the Python-ideas mailing list