Is there a straight-forward generator expression that can yield infinite elements?
This is a purely theoretical question. No need for a "practical" answer here :)
my_gen = (0 for i in xrange(42))
my_gen = _my_gen()
for x in iter(int, 1): pass
iter= zero-argument callable + sentinel value
iter(int, 1) is an infinite iterator. There are obviously a huge number of variations on this particular theme (especially once you add
lambda into the mix). One variant of particular note is
iter(f, object()), as using a freshly created object as the sentinel value almost guarantees an infinite iterator regardless of the callable used as the first argument.