Answers for "python n choose r"

1

python n choose r

# PYTHON 3.8
import math
math.comb(n, r)
Posted by: Guest on February-01-2022
-1

python choose function

>>> from math import comb
>>> comb(20,10)
Posted by: Guest on June-07-2020
0

python choose function

deck = range(1, 53) #get deck of cards from 1 to 52
comb = list(itertools.combinations(deck, 2)) # make list  with unic 2 cards combination
len(comb) #output 1326
Posted by: Guest on May-09-2020
0

python n choose r

# PYTHON <3.8
import operator as op
from functools import reduce

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom  # or / in Python 2
Posted by: Guest on February-01-2022

Python Answers by Framework

Browse Popular Code Answers by Language