[Python-ideas] More useful slices
Todd
toddrjen at gmail.com
Mon Feb 2 11:22:26 CET 2015
On Sun, Feb 1, 2015 at 10:51 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>
wrote:
> Todd wrote:
>
>> Although slices and ranges are used for different things and implemented
>> differently, conceptually they are similar: they define an integer sequence
>> with a start, stop, and step size.
>>
>
> They behave differently in some ways, though. Consider:
>
> >>> list(range(9,-1,-1))
> [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
>
> But:
>
> >>> x = list(range(10))
> >>> x
> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
> >>> x[9:-1:-1]
> []
>
> Would your proposed slice-ranges behave like slices or
> ranges in this situation? And how will people remember
> which?
>
Since this is really a literal for making ranges, I would say the range
syntax would be the correct one.
As I replied to Steven, let's forget the idea that slices and ranges are
the same. I was mistaken about that. Let's just call this a range
literal. It has some features similar to slices, but not all.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150202/093e18d9/attachment.html>
More information about the Python-ideas
mailing list