3 ms·
f = 0:1:zipWith (+) f (tail f)
by nh23423fefe 3y ago
f = 0:1:zipWith (+) f (tail f)
- Qem 3y agoIn 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.