1 2 3 4 5 6 7 8 9 10
def fib(max): '''iterator that yields numbers in the Fibonacci sequence''' a = 0 b = 1 yield a while b <= max: yield b a, b = b, a + b print list(fib(50))
1
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]