RosettaCodeData/Task/Fibonacci-sequence/Python/fibonacci-sequence-12.py

11 lines
256 B
Python
Raw Permalink Normal View History

2017-09-23 10:01:46 +02:00
def fib():
2018-06-22 20:57:24 +00:00
"""Yield fib[n+1] + fib[n]"""
yield 1 # have to start somewhere
lhs, rhs = fib(), fib()
yield next(lhs) # move lhs one iteration ahead
2017-09-23 10:01:46 +02:00
while True:
2018-06-22 20:57:24 +00:00
yield next(lhs)+next(rhs)
2017-09-23 10:01:46 +02:00
2018-06-22 20:57:24 +00:00
f=fib()
print [next(f) for _ in range(9)]