I am new to generator in python. I have a simple enough code which I am playing with but I can not understand the output I am getting out of it. Here is my code :
def do_gen():
for i in range(3):
yield i
def incr_gen(y):
return y + 1
def print_gen(x):
for i in x:
print i
x = do_gen()
y = (incr_gen(i) for i in x)
print_gen(x)
print_gen(y)
I expected my output to be like this :
0 1 2
1 2 3
But I am seeing only : 0 1 2
I do not understand this output. Can anyone please help me sort out my lack of understanding? Thanks in advance.