def Fibonacci(): def Refactor(): nonlocal fn, fn1, fn2 fn = 0; fn1 = fn yield fn # suspend def Refactor2(): nonlocal fn, fn1, fn2 fn = 1; fn2 = fn1; fn1 = fn yield fn # suspend yield from Refactor() yield from Refactor2() while True: fn = fn1 + fn2; fn2 = fn1; fn1 = fn; yield fn f1 = Fibonacci() f2 = Fibonacci() for i in range( 10 ): print( next( f1 ), next( f2 ) ) # resume # Local Variables: # # tab-width: 4 # # compile-command: "python3.5 FibRefactor.py" # # End: #