ztlevi
9/11/2017 - 3:28 PM

Generator!!!

Useful functions from itertools: islice, takewhile, dropwhile

from itertools import takewhile
print(list(takewhile(lambda x: x < 10, fib())))

>>>[1, 1, 2, 3, 5, 8]

from itertools import dropwhile
print(list(dropwhile(lambda x: x < 5,
                     takewhile(lambda x: x < 100,
                               islice(fib(), 15)))))

>>>[5, 8, 13, 21, 34, 55, 89]
def fib(a=1, b=1):
    while True:
        yield a
        a, b = b, a + b

from itertools import islice
print(list(islice(fib(), 10)))

>>>[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]