import itertools

- product() [중복 순열]

>>> import itertools
>>> a_li = [1, 2, 3]
>>> b_li = [4, 5]
>>> list(itertools.product(a_li, b_li))
[(1, 4), (1, 5), (2, 4), (2, 5), (3, 4), (3, 5)]

>>> ab_li = [[1, 2, 3], [4, 5]]
>>> list(itertools.product(*ab_li))
[(1, 4), (1, 5), (2, 4), (2, 5), (3, 4), (3, 5)] 

- permutations() [순열]

>>> import itertools
>>> li = [0, 1, 2]
>>> list(itertools.permutations(li, 2))
[(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1)] 

- combination() [조합]

>>> import itertools
>>> li = [0, 1, 2]
>>> list(itertools.combinations(li, 2))
[(0, 1), (0, 2), (1, 2)] 

댓글남기기