HiveBrain v1.2.0
Get Started
← Back to all entries
snippetpythonTip

Binomial coefficient

Submitted by: @import:30-seconds-of-code··
0
Viewed 0 times
pythoncoefficientbinomial

Problem

The binomial coefficient is the number of ways to choose k items from n items without repetition and without order. In Python, you can calculate the binomial coefficient using the math.comb() function.s

Solution

from math import comb

def binomial_coefficient(n, k):
  return comb(n, k)

binomial_coefficient(8, 2) # 28

Code Snippets

from math import comb

def binomial_coefficient(n, k):
  return comb(n, k)

binomial_coefficient(8, 2) # 28

Context

From 30-seconds-of-code: binomial-coefficient

Revisions (0)

No revisions yet.