deda
Deda의 데이터 디자인
deda
전체 방문자
오늘
어제
  • 분류 전체보기 (121)
    • Python (27)
      • Python 기초 (17)
      • Python 데이터분석 (10)
    • SQL (9)
    • Coding test (54)
      • Python 기초문제 (45)
      • LeetCode (9)
    • BigData (2)
    • ZeroBase (3)
    • UX (0)
    • Business Review (1)
    • 통계 & 수학 (17)
      • 통계학 (14)
      • 수학 (3)
    • 스터디 (6)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 프로그래밍
  • 팩토리얼
  • SQL
  • 기초수학
  • BMI
  • 네카라쿠배
  • 데이터분석
  • 통계
  • 데이터사이언티스트
  • matplotlib
  • 릿코드
  • 코딩
  • 파이썬
  • 계차수열
  • 데이터엔지니어
  • 등차수열
  • 데이터분석가
  • 미니콘다
  • 군수열
  • 빅데이터
  • 함수
  • 계산기
  • 부트캠프
  • pandas
  • 최소공배수
  • 제로베이스
  • 모듈
  • 등비수열
  • 소인수분해
  • 마이데이터

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
deda

Deda의 데이터 디자인

[모듈] 조합(combination)
Coding test/Python 기초문제

[모듈] 조합(combination)

2022. 4. 29. 16:51

🔍  문제

모듈을 사용하여 조합 출력

 

🗝 사용함수

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)
        resultR *= i

    resultC = int(resultP / resultR)         # p! / r!

    return resultC

from itertools import combinations

def getCombinations(ns, r):

    cList = list(combinations(ns, r))
    print(f'{len(ns)}C{r} : {len(cList)}')

    for i in combinations(ns, r):
        print(i, end='')
 

 

2) 실행_1

import combination1 as cb
numN = int(input('numN: '))
numR = int(input('numR: '))
print(f'{numN}C{numR} : {cb.combinationCnt(numN, numR)}')
 

 

3)실행_2

import combination1 as cb

cList = [1,2,7,8]
rVar = 2

cb.getCombinations(cList,rVar)
 

 

📝 결과물

사용자 모듈 사용
itertools 내 combinations 모듈 사용

 

 

[모듈] 순열 생성

🔍  문제 순열을 생성하는 모듈을 만들어 값을 구한다. 🗝 사용함수 nPr : n!/(n-r)! from itertools import permutations. :  itertools 패키지에 저장된 permutations(순열) 모듈 사용 permutations([a], b) :..

designingdata.tistory.com

 

[통계] 확률

🔍  확률 - 모든 경우의 수에 대한 특정 사건이 발생하는 비율 1. 표본 공간(Sample Space) -  표본 공간이란 어떤 실험에서 나올 수 있는 모든 가능한 결과들의 집합 -  동전 던지기의 경우 S = {앞

designingdata.tistory.com

 

'Coding test > Python 기초문제' 카테고리의 다른 글

[모듈] 사칙연산, 도형의 넓이 계산기  (0) 2022.04.30
[모듈] 공과금 계산하기  (0) 2022.04.29
[모듈] 순열(permutation)  (0) 2022.04.29
[모듈] 로또 번호 추출  (0) 2022.04.29
[모듈] 물건 가격 계산기  (0) 2022.04.29
    'Coding test/Python 기초문제' 카테고리의 다른 글
    • [모듈] 사칙연산, 도형의 넓이 계산기
    • [모듈] 공과금 계산하기
    • [모듈] 순열(permutation)
    • [모듈] 로또 번호 추출
    deda
    deda
    데이터 분석 / 파이썬 / UX / 정량리서치

    티스토리툴바