본문 바로가기

Programming Language/Python

Python itertools를 이용한 순열과 조합 (combinations, permutations)

1
2
3
4
5
6
7
8
9
10
11
12
13
import itertools
abc = [1,2,3,4]
#abc = ['a','b','c','d']
= itertools.permutations(abc, 3#target, length(Non-Essential)
 
for i in b:
    #i = list(i)
    print(list(i))
    
= itertools.combinations(abc, 2#target, length(Essential)
for i in b:
    #i = list(i)
    print(list(i))