In [1]:
def fibonacci(N):
a, b = 0, 1
while a < N:
yield a
a, b = b, a + b
In [2]:
list(fibonacci(100))
Out[2]:
In [3]:
%timeit fibonacci(10**4)