def fibonacci_iter(limit):
    a, b = 0, 1
while a < limit:
    yield a
a, b = b, a + b
print(sum(a for a in fibonacci_iter(4000000.0) if not a & 1))
Finding the sum of even valued terms in fibonacci sequence