PEP 276 Simple Iterator for ints

Jeff Shannon jeff at ccvcorp.com
Thu Nov 15 17:16:03 EST 2001


Ken Seehof wrote:

> Hey, what ever happened to the int[:10] iterator idea?
>
> >>> for i in int[2:10:2]: print i,
> 2 4 6 8
>

This doesn't look too bad to me.  I'd go for it.

>
> Hey, you could also do floats!
>
> >>> for x in float[ :1.0 : 0.2]: print x,
> 0.0 0.2 0.4 0.6 0.8
> >>> list(float[3.0:1.0:-0.5])
> [3.0, 2.5, 2.0, 1.5]

This *does* change syntax, though--currently only ints are allowed in slices,
and I think that's probably a good idea.  Besides, this would be just begging
for compounded floating-point-precision problems.

>
> Hmm.  Complex numbers?  Of course the step would be in radians :-)  heh heh.

Yikes!  Run away!!  :)

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list