육지_거북이 2021. 7. 29. 14:56

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