일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- sql
- programmers
- time complexity
- Growth hacking
- mysql
- LeetCode
- 조합
- python
- tableau
- 코딩테스트
- AARRR
- itertools
- lambda
- counter
- collections
- coding test
- join
- 완전탐색
- Queue
- lv4
- 코테
- 코딩
- coding
- 프로그래머스
- Level2
- Stack
- import re
- 파이썬
- cte
- level4
Archives
- Today
- Total
ror_coding
[Python] Permutations, Combination, Product (Itertools) 본문
Coding Test/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
'Coding Test > 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 |