Is there a direct generator expression that can produce infinite elements?
This is a purely theoretical question. No need for a βpracticalβ answer here :)
For example, it is easy to do the final generation:
my_gen = (0 for i in xrange(42))
However, to make it infinite, I need to "pollute" my namespace with a fake function:
def _my_gen(): while True: yield 0 my_gen = _my_gen()
The execution of actions in a separate file and import -ing are not taken into account later.
I also know that itertools.repeat does just that. I am curious if there is a one line solution without this.
python iterator generator infinite-loop
hugomg Apr 20 2018-11-21T00: 00Z
source share