일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- import re
- Stack
- mysql
- sql
- 시간복잡도
- BFS
- 연습문제
- 파이썬
- lambda
- coding test
- 조합
- time complexity
- join
- lv4
- 코테
- coding
- itertools
- collections
- Queue
- 완전탐색
- python
- level4
- 프로그래머스
- cte
- Level2
- programmers
- 코딩테스트
- counter
- 데이터분석
- 코딩
- Today
- Total
ror_coding
[Python] Permutations, Combination, Product (Itertools) 본문
Algorithm/Python
[Python] Permutations, Combination, Product (Itertools)
ro_rdil_31 2024. 12. 4. 14:59728x90
from itertools import
- permutations (순열)
- combinations (조합)
- product (주어진 반복 가능한 객체(iterable)들로 만들 수 있는 모든 조합 반환)
- cycle
from itertools import permutations as perm # 순열
from itertools import combinations as comb # 조합
from itertools import product # 모든 가능한 조합
from itertools import cycle
for p in perm(data): # 순열. (모든 경우의 수)
for c in comb(data, 3): # 3개씩 조합.
# product
l = [(x, -x) for x in numbers] # [(4, -4), (1, -1), (2, -2), (1, -1)]
s = list(map(sum, product(*l))) # *l는 위 list를 빼고 (4, -4) (1, -1)..
# product (완전탐색)
l1 = []
words = ['A','E','I','O','U']
for i in range(1,6): # 1~5
for j in list(product(words, repeat=i)): # repeat=i를 하면 i==2일 때, 'AA', 'AE'..반복 저장.
l1.append(''.join(j))
728x90
'Algorithm > Python' 카테고리의 다른 글
[Programmers] 튜플 - 64065 (0) | 2024.12.04 |
---|---|
[Python] re (정규표현식) (0) | 2024.12.04 |
[Programmers] 피로도 - 87946 (3) | 2024.12.04 |
[Programmers] 의상 - 42578 (2) | 2024.12.02 |
[Python] Stack, Queue (collections) (deque) (0) | 2024.12.02 |