패키지

    [모듈] 조합(combination)

    [모듈] 조합(combination)

    🔍 문제 모듈을 사용하여 조합 출력 🗝 사용함수 nCr : nPr/r! = n!/(n-r)! from itertools import combinations. : itertools 패키지에 저장된 combinations(순열) 모듈 사용 combinations([a], b) : 리스트 a에서 b개를 순서와 상관없이뽑음 list(permutations([a], b)) : 위 결과를 리스트로 출력 🖥 실행 1) 모듈 생성 def combinationCnt(n,r): # n! / (n-r)!*r! resultP = 1 resultC = 1 resultR = 1 for i in range(n, n-r, -1): resultP *= i for i in range(1,r+1): # 또는 range(r, 0, -1) ..