Skip to content Skip to sidebar Skip to footer

Python Generator Yields Same Value Each Call

I want this generator to yield the cosine of each successive value from a list, but am getting the same value each time. import math angles = range(0,361,3) # calculate x coo

Solution 1:

Every time you call calc_x you create a new generator. What you need to do is create one and then keep using it:

calc = calc_x(angles)
next(calc)
next(calc)
# etc.

Post a Comment for "Python Generator Yields Same Value Each Call"