1 def C(n, i):
2     cache2 = dict()
3     def f(n, i):
4         if n == i or i == 0:
5             return 1
6         elif (n, i) not in cache2:
7             cache2[(n, i)] = f(n - 1, i) + f(n - 1, i - 1)
8         return cache2[(n, i)]
9     return f(n, i)

 

1 from functools import lru_cache
2 @lru_cache(maxsize=64)
3 def C(n, i):
4     if n == i or i == 0:
5         return 1
6     return C(n - 1, i) + C(n - 1, i - 1)