18 ms·
In Python is possible to do something quite similar, using itertools: from itertools import pairwise, chain def f(): yield from chain([0,1], map(sum,
by Qem 3y ago
In Python is possible to do something quite similar, using itertools:
from itertools import pairwise, chain
def f(): yield from chain([0,1], map(sum, pairwise(f())))
There's a Joel Grus post discussing it: https://joelgrus.com/2015/07/07/haskell-style-fibonacci-in-python/ https://joelgrus.com/2015/07/07/haskell-style-fibonacci-in-p...
The introduction of pairwise in 3.10 made possible to write it more compactly, when compared to the version discussed by Joel.