import itertools def fib(): a, b = 0, 1 while True: yield b a, b = b, a+b print sum(itertools.takewhile(lambda x: x < 400, fib)) ----------------------- I tried the above; and it worked too (986) Asokan Pichai