Reputation: 21
I don`t understand how exactly should I use loop for to call all operations instead of using 'print (next(generator))
I have a generator function and I need to print all elements in the list
def gen(a,b)... #there is a generator function
for i in gen(a,b):
print (next(gen(a,b)))
where is the problem?
Upvotes: 0
Views: 65
Reputation: 45726
i
is the value produced by your generator. With your current code, you're ignoring i
, and creating a new generator in each iteration, then taking the first element of that new iterator.
You simply need:
for i in gen(a,b):
print(i)
Upvotes: 1