def Fib(): def Refactor(): nonlocal fn, fn1 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 = Fib() f2 = Fib() for i in range( 10 ): print( next( f1 ), next( f2 ) ) # resume # Local Variables: # # tab-width: 4 # # compile-command: "python3.7 FibRefactor.py" # # End: #