fredrik at pythonware.com
Wed Nov 24 15:06:03 CET 1999
Markus Stenberg <mstenber at cc.Helsinki.FI> wrote:
> > - a less yucky way of saying "for i in range(1,20,3)"
> see above - although some special syntactic sugar would be "nice", I prefer
> minimalistic approach over say, C.. of course, Dylan does it (IMNSHO)
> for (i from 3 to 19 by 3)
note that python already has a special syntax
for this purpose:
>>> a = range(20)
>>> print a[1:20:3]
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: sequence index must be integer
(note that you got a type error, not a syntax
error. numpy arrays fully support this syntax).
in other words, you don't have to be guido to
realize that something like:
for i in [1:20:3]:
could be the right way to do it in Python. in
fact, it's already on the list for 2.0:
More information about the Python-list