number ranges (was Re: Matlab page on scipy wiki)
John Zenger
john_zenger at yahoo.com
Sun Feb 19 23:32:16 EST 2006
Colin J. Williams wrote:
> Bryan Cole wrote:
>
>>>
>>> First, I think the range() function in python is ugly to begin with.
>>> Why can't python just support range notation directly like 'for a in
>>> 0:10'. Or with 0..10 or 0...10 syntax. That seems to make a lot more
>>> sense to me than having to call a named function. Anyway, that's a
>>> python pet peeve, and python's probably not going to change something
>>> so fundamental...
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. Every maths text I have read uses the ".." notation to show
ranges; for that reason, perhaps, Haskell uses "..". The colon is
already overused; it both signals the beginning of compound statements,
and has all sorts of slice/indexing meanings when it is inside square
brackets, depending on how many colons there are and whether there are
arguments between them.
Haskell also has a good step notation. In Haskell:
[1..10] means [1,2,3,4,5,6,7,8,9,10]
[1,3..10] means [1,3,5,7,9]
More information about the Python-list
mailing list