permutations (์์ด)
iterable ๊ฐ์ฒด์์ n๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ๋ฝ์ ์ผ๋ ฌ๋ก ๋์ดํ๋ ๋ชจ๋ ๊ฒฝ์ฐ
product (์ค๋ณต์์ด)
iterable ๊ฐ์ฒด์์ ์ค๋ณต์ ํ์ฉํ์ฌ n๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ๋ฝ์ ์ผ๋ ฌ๋ก ๋์ดํ๋ ๋ชจ๋ ๊ฒฝ์ฐ
combinations (์กฐํฉ)
iterable ๊ฐ์ฒด์์ n๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ๋ฝ์ ์์๋ฅผ ๊ณ ๋ คํ์ง ์๊ณ ๋์ดํ๋ ๋ชจ๋ ๊ฒฝ์ฐ
combinations_with_replacement (์ค๋ณต์กฐํฉ)
iterable ๊ฐ์ฒด์์ ์ค๋ณต์ ํ์ฉํ์ฌ n๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ๋ฝ์ ์์๋ฅผ ๊ณ ๋ คํ์ง ์๊ณ ๋์ดํ๋ ๋ชจ๋ ๊ฒฝ์ฐ
์ด๋ฅผ ์ฌ์ฉํ ์์๋ ์๋์ ๊ฐ๋ค.
from itertools import combinations, combinations_with_replacement, permutations, product
data = ['A','B','C']
permutations_result = list(permutations(data,2))
product_result = list(product(data, repeat=2))
combinations_result = list(combinations(data,2))
combinations_with_replacement_result = list(combinations_with_replacement(data,2))
print(permutations_result)
# [('A', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'C'), ('C', 'A'), ('C', 'B')]
print(product_result)
# [('A', 'A'), ('A', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'B'), ('B', 'C'), ('C', 'A'), ('C', 'B'), ('C', 'C')]
print(combinations_result)
#[('A', 'B'), ('A', 'C'), ('B', 'C')]
print(combinations_with_replacement_result)
#[('A', 'A'), ('A', 'B'), ('A', 'C'), ('B', 'B'), ('B', 'C'), ('C', 'C')]
'๐ฆ Computer Language > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python] Collections - deque | ๊ฐ๋ , ๋ฉ์๋, list์์ ์ฐจ์ด (0) | 2021.07.19 |
---|---|
[Python] list B = A์ B = A[:]์ ์ฐจ์ด (0) | 2021.07.14 |
[Python] 2์ฐจ์ ๋ฐฐ์ด์์ ์ต๋๊ฐ๊ณผ ์ต์๊ฐ ๊ตฌํ๊ธฐ (0) | 2021.07.12 |
[Python] ๊ธธ์ด๊ฐ ์ ํด์ง ๋ฆฌ์คํธ ๋ง๋ค๊ณ 0์ผ๋ก ์ด๊ธฐํํ๊ธฐ (0) | 2021.07.03 |
[Python][Error] KeyError: 0 (0) | 2021.06.30 |