def comb(N, k):
    if k > N or N < 0 or k < 0:
        return 0
N, k = map(int, (N, k))
top = N
val = 1
while top > N - k:
    val *= top
top -= 1
n = 1
while n < k + 1:
    val /= n
n += 1
return val
Statistics: combinations in Python