I know that the following is a suboptimal implementation of a fibonacci generator compared to this, but I cannot seem to understand why it is not working as expected:
def fibonacci_sequence():
fl, fp = 1, 1
while True:
yield (fl + fp)
store = fl + fp
fp = fl
fl = store
for i in range(10):
print(next(fibonacci_sequence()))
It keeps printing 2 all the time.
Isn't the generator's state being updated underneath yield
keyword on each iteration?