PEP 276 Simple Iterator for ints
cliechti at gmx.net
Thu Nov 15 21:18:25 CET 2001
"Ken Seehof" <kseehof at neuralintegrator.com> wrote in
news:mailman.1005848962.18049.python-list at python.org:
> Hey, what ever happened to the int[:10] iterator idea?
>>>> for i in int[2:10:2]: print i, 2 4 6 8
I've played around with an implementation for that and I like it.
> Like PEP 276, it doesn't require new syntax (just implement a slice
> operator for int).
> int[3:8] should return an iterator equivalent to [3,4,5,6,7]
> int[-4::2] should return an infinite sequence iterator [-4, -2, 0, 2,
> I think that this solves all of the problems that PEP 276 solves,
> without any inconsistent idioms or warts.
i think the advantage of pep 276 would be that you don't need to write an
extra word "for i in 10:" as oposed to "for i in int[:10]:".
but i don't like the pep 276 syntax much. i think its better when you see
that its a sequence and just a number realy isn't a sequence. (yes i know
it would return an iterator but an iterator just returns the elements of a
sequence, even if the values are calculated)
> Here's what http://python.sourceforge.net/peps/pep-0276.html has to
> say about it:
> - It would be better to reuse the slicing literal syntax attached
> to the int class, e.g., int[0:10]
> Response: Same as previous response.
> """ Response: Shares disadvantages of other proposals that
> changes to the syntax. Needs more design to determine how it
> would handle the general case of start,stop,step,
> open/closed/half-closed intervals, etc. Needs a PEP."""
> In addition, design
> consideration needs to be given to what it would mean if one
> uses slicing syntax after some arbitrary class other than class
> int. Needs a PEP.
> What syntax change? There is no syntax change. A slice operator would
> simply be added to the int class. Slicing syntax applied to some
> arbitrary class would naturally depend on the slice implementation for
> that class :-) I agree that it needs a PEP.
> 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
> [3.0, 2.5, 2.0, 1.5]
and that would be an advantage over [x]range()!
> Hmm. Complex numbers? Of course the step would be in radians :-) heh
what do you want? drawing circles? ;-)
> - Ken
Chris <cliechti at gmx.net>
More information about the Python-list