[Python-ideas] Builtin infinite generator

Tobias Ivarsson thobes at gmail.com
Wed Mar 21 17:57:44 CET 2007


Quite often I find myself wanting to write an infinite for-loop, or rather a
loop with a counter, that terminates on some inner condition. Recently I
even wanted to do this together with the generator comprehension syntax, I
don't remember exactly what I wanted to do, but it was something like:
zip( some_list_of_unknown_length, ('a' for x in infinit_generator) )
I admit that my example is silly, but it still serves as an example of what
I wanted to do.

Then I read that Ellipsis will become generally accepted in py3k [1] and
thought why not let range accept ... as end-parameter to mean "until
forever".

More silly examples to demonstrate how it would work:

>>> for i in range(...):
...     print i
...     if i == 4: break
0
1
2
3
4
>>> for i in range(10,...,10):
...     print i
...     if i == 40: break
10
20
30
40

Any thoughts on this?

/Tobias

[1] http://mail.python.org/pipermail/python-3000/2006-April/000996.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20070321/94d7fa82/attachment.html>


More information about the Python-ideas mailing list