By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

range syntax

P: n/a
One of the little irritants of Python is that the range syntax is rather
long-winded:
[Dbg]>>range(3, 20, 6)
[3, 9, 15]
[Dbg]>>>
It would be nice if one could have something like 3:20:6.

I've just come across the r_class in numpy which doesn't go that far
but does provide a generalization of the above:
[Dbg]>>r_[1:6:2, 6:8, (10, 11, 13), [20,25]]
array([ 1, 3, 5, 6, 7, 10, 11, 13, 20, 25])
[Dbg]>>>

Colin W.

Nov 10 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Colin J. Williams wrote:
One of the little irritants of Python is that the range syntax is rather
long-winded:
[Dbg]>>range(3, 20, 6)
[3, 9, 15]
[Dbg]>>>
It would be nice if one could have something like 3:20:6.
In that case, how would the parser know which colon terminates the
'for' in the following example:

for i in 2:3:4:
...

--
Roberto Bonvallet
Nov 10 '06 #2

P: n/a
On 2006-11-10, Roberto Bonvallet <Ro***************@cern.chwrote:
Colin J. Williams wrote:
>One of the little irritants of Python is that the range syntax is rather
long-winded:
[Dbg]>>range(3, 20, 6)
[3, 9, 15]
[Dbg]>>>
It would be nice if one could have something like 3:20:6.

In that case, how would the parser know which colon terminates the
'for' in the following example:

for i in 2:3:4:
...
By the programmer using parenthesis. Like

for i in (2:3):
...
Just as you are supposed to use parthesis if you
want a tuple as a function argument although normally
a comma is enough to form a tuple.

--
Antoon Pardon
Nov 10 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.