표준 라이브러리
내장 함수 : sum(), min(), max(), sorted()
참고로 pow(a,b,n) 함수는 아래와 같이 작동하지만
저렇게 작성한 것 보다 훨씬 효율적으로 작동하여 시간차이 많이남.
x = a**d % n
아래 참고
Why is pow(a, d, n) so much faster than a**d % n?
I was trying to implement a Miller-Rabin primality test, and was puzzled why it was taking so long (> 20 seconds) for midsize numbers (~7 digits). I eventually found the following line of code to b...
stackoverflow.com
itertools : 순열, 조합 라이브러리 - 완전 탐색 문제 풀이시 사용됨
파이썬(python) 라이브러리 - itertools (순열, 조합, 누적합)
itertools 라이브러리 순열 : 서로다른 n개 에서 서로 다른 r개 선택하여 순서대로 나열 list(permutations(data, 선택할 개수)) from itertools import permutations a=list(permutations(data,1)) b=list(permut..
11001.tistory.com
heapq : 힙 자료구조 제공. 우선순위 큐 기능 구현 시 사용됨
파이썬(python) 라이브러리 - heapq
heapq 파이썬에서 힙 (우선순위 큐) 자료구조를 이용할때 사용한다. C++, 자바는 우선순위 큐 자료구조를 제공하지만 파이썬은 리스트를 우선순위 큐 처럼 다룰 수 있는 함수를 제공한다. 최소 힙 (
11001.tistory.com
bisect : 이진 탐색 기능 제공
파이썬(python) 라이브러리 - bisect (이진탐색, 바이너리 서치, Binary Search)
이진탐색 (바이너리 서치, Binary Search) 정렬된 리스트에서 탐색 범위를 절반씩 좁혀나가며 빠르게 탐색하는 방법 특징 탐색 범위가 매우 크게 주어짐 O(n) 인 선형탐색으로는 시간초과 나는 경우
11001.tistory.com
collections : 덱, 카운터 자료구조 제공
파이썬(python) 라이브러리 - collections.Counter
collections.Counter(iterbale) iterbale 객체의 각 요소의 등장 횟수를 세는 기능 리스트에 음수가 있으면 안됨 !!!!!!!!!!!!!!! import collections a = [1,2,3,1,2,3,3,4] b = collections.Counter(a) : 등장..
11001.tistory.com
파이썬(python) 라이브러리 - collections.deque
collections.deque 파이썬에서 queue를 이용할때 사용한다. list를 이용하면 add 연산에 O(n) 만큼의 시간이 들기 때문에 deque를 사용해야함. 데이터가 오른쪽으로 추가되고 왼쪽으로 나가는 형태 q = collect
11001.tistory.com
math : 수학적 기능 제공. 팩토리얼(factorial), 제곱근(sqrt), 최대공약수(gcd) 등
최소공배수(lcm) 는 파이썬 3.9이상에서 제공.
그 이전에는 아래와 같이 구현
def lcm(a,b):
return a*b//math.gcd(a,b)
'Python > 라이브러리' 카테고리의 다른 글
파이썬(python) 라이브러리 - bisect (이진탐색, 바이너리 서치, Binary Search) (0) | 2021.04.21 |
---|---|
파이썬(python) 라이브러리 - collections.Counter (0) | 2021.04.21 |
파이썬(python) 라이브러리 - itertools (순열, 조합, 누적합) (0) | 2021.04.21 |
파이썬 라이브러리 - datetime (0) | 2021.03.23 |
파이썬 (python) 라이브러리 - Pandas 판다스 (0) | 2021.03.22 |