from functools import reduce
def nck_safe(n, k):
    if k < 0 or n < k:
        return 0
return reduce(mul, list(range(n, n - k, -1)), 1) // reduce(mul, list(range(1, k + 1)), 1)
Find the index of a given combination (of natural numbers) among those returned by `itertools` Python module