number ranges (was Re: Matlab page on scipy wiki)

John Zenger john_zenger at yahoo.com
Mon Feb 20 10:09:55 EST 2006


Steven D'Aprano wrote:
> John Zenger wrote:
> 
>> I strongly agree that Python should promote range or xrange to syntax. 
>> I favor [0..10] rather than [0:10] because 0..10 is inherently easier 
>> to understand.
 >
> "Inherently"?
> 
> You mean people are born with an instinctive, unlearnt understanding of 
> ..? 

I mean that most people will have seen that notation somewhere else in 
their pre-Python lives, so it won't take much effort for them to 
remember what it is, at least more so than 0:10.

> With the 
> introduction of a single keyword, we could do this:
> 
> for i in 2 to 5:
>     print i,
> 
> which would print 2 3 4 5

This proposed syntax is also easy to understand, maybe more than "..", 
because it uses natural language.  The only criticism is that it creates 
a list without using [] notation.  How about [2 to 5]?

> 
> (I'm open to arguments that it should be more Pythonic and less 
> mathematical, and halt at 4.)

I am also open to such arguments but it will be tough to convince me 
that "x to y" should mean something different from what it means in 
Pascal, BASIC, and English.

> 
> A second keyword "downto" would allow easy backwards loops,

"Downto" would only be necessary if we wanted "[10 to 1]" to equal [].

> and a third 
> "step" will absolutely kill any chance of Guido agreeing to this 
> whatsoever.

What about [1 to 3 to 10]?  (Or [1 to 10:2]?)



More information about the Python-list mailing list