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]:
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]

In [3]:
%timeit fibonacci(10**4)


The slowest run took 11.15 times longer than the fastest. This could mean that an intermediate result is being cached 
10000000 loops, best of 3: 192 ns per loop