Just for fun and out of curiosity, I devised this way of writing a generator that counts to infinity, at least in principle. Nothing very pythonian. Just playing around.
But obviously with each iteration lis
gets longer until something will eventually break.
Are there other (better or worse) ways to achieve the same goal? Please share.
lis = [1]
gen = ((k, lis.append(k+1))[0] for k in lis)
To use it
for j in gen:
print(j)