1. 순열
import itertools
color_list = ['red','blue','green']
nPr = itertools.permutations(color_list, 2)
print(list(nPr))
[('red', 'blue'), ('red', 'green'), ('blue', 'red'), ('blue', 'green'), ('green', 'red'), ('green', 'blue')]
순서를 고려하여 즉 (a,b)와 (b,a)를 다른 것으로 치고 뽑기
itertools.permutations(list, n)
list에서 n개를 뽑는경우
2. 조합
nCr = itertools.combinations(color_list, 2)
print(list(nCr))
[('red', 'blue'), ('red', 'green'), ('red', 'orange'), ('blue', 'green'), ('blue', 'orange'), ('green', 'orange')]
순서를 고려하여 즉 (a,b)와 (b,a)를 같은 것으로 치고 뽑기
itertools.combinations(list, n)
list에서 n개를 뽑는경우
'python 기초' 카테고리의 다른 글
[python 기초] random 모듈, 무작위 추출 (0) | 2021.12.21 |
---|---|
[python 기초] 알파벳 리스트만들기 string 모듈 (0) | 2021.12.21 |
[python 기초] 변수명에 format 사용 변수명 for문 (0) | 2021.12.06 |
[python기초] tqdm for문 예상속도, time (0) | 2021.12.06 |
[ python 기초 ] lambda, map, filter (0) | 2021.08.27 |