Ofer Koren
Nov 23, 2020

--

You've basically wrote the Iterative version of Fibonacci (which is naturally more performant), just more complicated…

The behavior you get, of a function that returns the next value with each call, is better implemented using a python generator:

def fib():
x0, x1 = 0, 1
while True:
yield x0
x0, x1 = x1, x0 + x1

--

--

Ofer Koren
Ofer Koren

Written by Ofer Koren

A pythonist at heart, dabbling in Devops and Automations of various kinds

No responses yet