a, b = 0, 1
total = 0
while b < 4000000:
    a, b = b, a + b
    if b % 2 == 0:
        total += b

print total

def fib():
    a, b = 0, 1
    while True:
        yield b
        a, b = b, a + b

total = 0
i = 0
for i in fib():
    if i >= 4000000:
        break
    if i % 2 == 0:
        total += i

print total

restructure python 2 to use a generator