# coding=utf-8
from itertools import permutations
from itertools import combinations
from itertools import product
from itertools import combinations_with_replacement
a = []
b = []
c = []
d = []
items= [1,2,3,4]
#순열
for i in list(permutations(items, 2)):
a.append(i)
print(a)
#중복 순열
for i in list(product(items, repeat=2)):
c.append(i)
print(c)
#조합
for i in list(combinations(items, 2)):
b.append(i)
print(b)
#중복조함
for i in list(combinations_with_replacement(items, 2)):
d.append(i)
print(d)
결과
[(1, 2), (1, 3), (1, 4), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (3, 4), (4, 1), (4, 2), (4, 3)]
[(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2), (2, 3), (2, 4), (3, 1), (3, 2), (3, 3), (3, 4), (4, 1), (4, 2), (4, 3), (4, 4)]
[(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
[(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)]
'python' 카테고리의 다른 글
[Python] enumerate (0) | 2020.06.29 |
---|---|
[Python] for문 index로 접근 (0) | 2020.05.28 |
[Python] isdigit(), isalpha()함수 (0) | 2020.05.25 |
[Python] 문자열 나누기(split) (0) | 2020.05.19 |
[Python] 문자열을 한 글자씩 리스트로 저장하기 (0) | 2020.05.19 |