Operations on infinite lists
In this example we multiply each value by 2. (I know it is not the most sophisticated mathematical problem, but it will work for this example.)
The variable double_fibonacci holds the values of the Fibonacci series multiplied by 2. More precisely it holds the possibility to iterate over that infinite list.
So in reality we don't operate on the infinite lists, only on the "potential of the lists", but the former sounds cooler.
Try running it without the if and break statements and see what happens. (Ctrl-C will stop the program.)
examples/generators/infinite_operations.py
def fibonacci(): a, b = 0, 1 while True: a, b = b, a+b yield a double_fibonacci = (value * 2 for value in fibonacci()) for a in double_fibonacci: print(a) if a > 200: break
2 2 4 6 10 16 26 42 68 110 178 288