def function():
for i in range(5):
yield i
gen = function()
print("length of gen: ", len(list(gen)))
for i in gen:
print(i)
assert i == 200
I don't think I understand how generators work. When I run the above code, it seems there is no iteration over gen
because nothing is printing within the for loop and the assertion isn't being evaluated. How can I iterate over the generator properly?