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

Paul Moore p.f.moore at gmail.com
Wed Oct 30 12:35:59 CET 2013


On 30 October 2013 10:18, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>     b = a[::-1]
>>
>> over
>>
>>     b = a[Slice(None, None, None, reversed=True)]
>>
>> I could probably omit some of those None arguments, but I probably
>> wouldn't simply because I can't remember which are optional.
>
> Why does that give you trouble when it's identical to what you can
> omit from the normal slice syntax? (and from range)

slice(reversed=True)?

I can omit all the arguments in the indexing case (OK, I enter a step
of -1, but that's equivalent to reversed=True and a step of 1, which
is default). And yet currently slice() fails as a minimum of 1
argument is needed.

I'm not saying that it's ill-defined, just that I'd get confused fast.
So "better to be explicit" (but verbose). And [::-1] is clear and
simple (to me, at least).

Paul


More information about the Python-ideas mailing list