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

Jan Kaliszewski zuo at chopin.edu.pl
Mon Oct 28 02:59:41 CET 2013


2013-10-27, 21:44, Guido van Rossum wrote:

> On Sun, Oct 27, 2013 at 11:38 AM, Tim Peters <tim.peters at gmail.com> 
> wrote:
[...]
> If I could do it over I would do it this way.
>
>> So it's always a semi-open range, inclusive "at the left" and
>> exclusive "at the right".  But that's more a detail:  the _point_ is
>> to preserve the mental model of selecting the elements "between
>> position".  Of course I'd change range() similarly.
>
> Which probably would cause more backward incompatibility bugs,
> since by now many people have figured out that if you want
> [4, 3, 2, 1, 0] you have to write range(4, -1, -1). :-(

Maybe introduction of a new builtin and deprecation of range()
could be the remedy?  The new builtin, named e.g. "scope", could
even be combination of todays range + slice?

     >>> list(scope(0, 5, -1))        # Py 3.5+
     [4, 3, 2, 1, 0]
     >>>> 'abcdef'[scope(0, 5, -1)]   # Py 3.5+
     'edcba'
     >>>> 'abcdef'[0:5:-1]            # Py 4.0+
     'edcba'

It's just a loud thinking...

Cheers.
*j



More information about the Python-ideas mailing list