🌼 실전에서 자주 사용되는 표준 라이브러리
1. itertools: 반복되는 형태의 데이터 처리를 위한 함수 제공
- ex) 순열 조합
2. heapq: 힙(Heap) 자료구조 제공
- 일반적으로 우선순위큐 구현시 사용
3. bisect: 이진 탐색(Binary Search) 기능을 제공
4. collections: 데크(dequeue), 카운터(Counter) 등의 자료구조 제공
5. amth: 필수적인 수학적 기능 제공
- ex) 팩토리얼, 최대 공약수(GDC), 최소 공배수(LCM), 파이(Pi) 등 제공
🌼 순열과 조합 - itertools 라이브러리
- 순열 (permutations)
- 서로 다른 n개에서 서로 다른 r개를 선택하여 일렬로 정렬(순서 고려)
- 중복고려 버전 > product()
- 조합 (combinations)
- 서로 다른 n개에서 서로 다른 r개를 선택 (순서 고려 X)
- 중복고려 버전 > combinations_with_replacement()
🌼 Counter - collections 라이브러리
- 등장 횟수를 세는 라이브러리
from collections import Counter
arr = ['blue', 'blue', 'red', 'blue', 'red', 'yellow', 'blue']
counter = Counter(arr)
print(counter['red'])
print(counter['blue'])
print(counter['yellow'])
print(dict(counter))
# 출력 결과
# 2
# 4
# 1
# {'blue': 4, 'red': 2, 'yellow': 1}
🌼 최대공약수와 최소공배수 - math 라이브러리
- 최대공약수 - GCD
- 최소공배수 - LCM
728x90
'Algorithm&CodingTest > 이것이 코딩테스트다 with 파이썬' 카테고리의 다른 글
🌼 Dijkstra Algorithm(다익스트라 알고리즘) 최단경로 알고리즘 (0) | 2024.10.04 |
---|---|
🌼 DFS & BFS 기초 문제 풀이 (0) | 2024.10.02 |
🌼 BFS(Breath-First-Search) Algorithm (0) | 2024.10.02 |
🌼 DFS(Depth-First-Search) Algorithm (0) | 2024.10.02 |
🌼 Greedy Algorithm (탐욕 알고리즘) (1) | 2024.10.01 |