[0..9] list (range) syntax

Michal Bozon bozonm at vscht.cz
Thu Oct 25 02:22:21 CEST 2007


On Thu, 25 Oct 2007 01:16:57 +0200, Wildemar Wildenburger wrote:

> Michal Bozon wrote:
>> many Python newcomers are confused why
>> range(10), does not include 10.
>> 
> It produces a list of ten elements. Also the documentation is quite 
> clear on the topic. And lastly: This will probably really bother you for 
> a week, then no more.
> 
> 
>> If there was a proposal for the new
>> syntax for ranges, which is known
>> e.g. from Pascal or Ruby...
>> 
>>>>> [0..10]
>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>> 
>> ...is there a chance to be approved ?
>> 
> Quite close to none. It is too much cosmetics and too little 
> enhancement. What would that make possible that is impossible by now or 
> what would that make easier that is really hard?
> 
> And if you really need something like that, write a function:
> 
> def fullrange(start, end):
>      r = range(start, end)
>      r.append(end)
>      return r
> 
> /W

This is something completely different.
The .. syntax was not meant only as something
which would include the last item,
but also/rather a range list syntactic shortcut:

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] -->
[0, 1, ... 9, 10] -->
[0..10]

 -m.



More information about the Python-list mailing list