iters on ints? (reducing the need for range/xrange)
wtanksle at dolphin.openprojects.net
Sat Nov 10 00:30:25 CET 2001
On Fri, 9 Nov 2001 16:04:11 GMT, Michael Hudson wrote:
>Paul Rubin <phr-n2001d at nightsong.com> writes:
>> Really the ellipsis should make an iterator: for i in 0...10.
>It's probably worth reading the rejected pep on range literals:
Facinating. The syntax of this proposal makes me think that he's trying
to slice an array of nothing (there's no array there), whch seemed to be
What if slicing/indexing the "int" builtin resulted in a generator with
the desired behavior?
for x in int:
for x in int[1:11]:
for x in int[1:11:2]:
# now some hard ones
for x in int[0:]: # all the natural numbers
for x in int[0::2]: # all the even naturals
for x in int[:0]: # illegal
for x in int[:0:-1]: legal, all negative numbers
Wait -- a question. Do slices act on generators? That is, can I slice
out every other item of a generator (as I just did above)? If not, could
that be added? Once that's added, what's to stop me from annoyingly
demanding to be able to slice out every 'n'th item (keeping the rest as
part of the generated sequence)? Such a thing would feed my hunger for an
interesting prime # sieve...
Wait, I'm hearing a voice. It tells me, "WRITE A PEP."
Never mind -- I got my answer; I now know what will stop me from demanding
those things. Odd, I feel stopped on my current demands as well. :-)
> I would hereby duly point you at the website for the current pedal
> powered submarine world underwater speed record, except I've lost
> the URL. -- Callas, cam.misc
Hey, a friend of mine set that record. I wonder if it's still standing...
-William "Billy" Tanksley
More information about the Python-list