RosettaCodeData/Task/Fibonacci-sequence/Python/fibonacci-sequence-16.py
2026-02-01 16:33:20 -08:00

17 lines
337 B
Python

def nth_fib(n):
"""Nth Fibonacci term (by folding)
Nth integer in the Fibonacci series.
"""
from functools import reduce
return reduce(
lambda acc, _: (acc[1], sum(acc)),
range(1, n),
(0, 1)
)[0]
# MAIN ---
if __name__ == '__main__':
n = 1000
print(f'{n}th term: {nth_fib(n)}')