본문 바로가기

프로그래밍 언어/python

수학

1. 순열 / 조합

1) 순열 : permutations(배열 이름, r)

   - from itertools import permutations 

   - 배열의 원소 중 2개 뽑아서 출력하기 :  for i in permutations(배열 이름, 2): print(i)
   - 배열의 원소 중 2개 뽑아서 리스트 만들기 : list( map(''.join, permutations(배열이름,2) ) 

 

2) 중복 순열 : product(배열 이름, repeat= r)

   - from itertools import product 

   - 배열의 원소 중 2개 뽑아서 출력하기 :  for i in product(배열 이름, repeat = 2): print(i)
   - 배열의 원소 중 2개 뽑아서 리스트 만들기 : list( map(''.join, permutations(배열이름,repeat = 2) ) 

 

3) 조합 : Combinations(배열 이름, r)

   - from itertools import Combinations

   - 배열의 원소 중 2개 뽑아서 출력하기 :  for i in Combinations(배열 이름, 2): print(i)
   - 배열의 원소 중 2개 뽑아서 리스트 만들기 : list( map(''.join, Combinations(배열이름, 2) ) 

 

4) 중복 조합 :combinations_with_replacement(배열 이름, r)

   - from itertools import combinations_with_replacement as combi

 

'프로그래밍 언어 > python' 카테고리의 다른 글

입/출력  (0) 2021.08.02
정렬  (0) 2021.08.01
python 에러 모음  (0) 2021.07.28
python 기초 - 구현  (0) 2021.07.24
python 기초 - 배열1  (0) 2021.07.23