Skip to content

Instantly share code, notes, and snippets.

@tusharsadhwani
Created May 5, 2021 20:27
#test.py
cache = {}
def fibonacci(n):
"""Fibonacci series implementation"""
if n <= 1:
return 1
if n in cache:
return cache[n]
result = fibonacci(n-1) + fibonacci(n-2)
cache[n] = result
return result
for i in range(6):
print(fibonacci(i))
# Output:
# 1
# 1
# 2
# 3
# 5
# 8
# test.pyi
from typing import Dict
cache: Dict[int, int]
def fibonacci(n: int) -> int: ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment