250x250
반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- session 유지
- subdag
- Counterfactual Explanations
- spark udf
- 유튜브 API
- requests
- login crawling
- top_k
- Retry
- integrated gradient
- 공분산
- GCP
- API
- grad-cam
- UDF
- TensorFlow
- flask
- youtube data
- 상관관계
- API Gateway
- hadoop
- airflow subdag
- gather_nd
- BigQuery
- GenericGBQException
- tensorflow text
- XAI
- correlation
- chatGPT
- Airflow
Archives
- Today
- Total
데이터과학 삼학년
Python deque 본문
반응형
데크(deque)의 개념
보통 큐(queue)는 선입선출(FIFO) 방식으로 작동한다. 반면, 양방향 큐가 있는데 그것이 바로 데크(deque)다.
즉, 앞, 뒤 양쪽 방향에서 엘리먼트(element)를 추가하거나 제거할 수 있다.
데크는 양 끝 엘리먼트의 append와 pop이 압도적으로 빠르다.
컨테이너(container)의 양끝 엘리먼트(element)에 접근하여 삽입 또는 제거를 할 경우, 일반적인 리스트(list)가 이러한 연산에 O(n)이 소요되는 데 반해, 데크(deque)는 O(1)로 접근 가능하다.
from collections import deque
deq = deque()
# Add element to the start
deq.appendleft(10)
# Add element to the end
deq.append(0)
# Pop element from the start
deq.popleft()
# Pop element from the end
deq.pop()
* deque를 이용해 큐와 스택을 모두 구현 가능
728x90
반응형
LIST
'Python' 카테고리의 다른 글
Modin : Use modin to replace pandas in larger data (0) | 2022.03.31 |
---|---|
내 코드를 테스트한다. (feat. pytest) (0) | 2022.03.28 |
파이썬 패키지 개념 (feat. 코딩도장) (0) | 2021.11.15 |
에라토스테네스의 체 (소수 구하기) (0) | 2021.10.20 |
리스트 정렬 (multiple key를 이용한 정렬) (0) | 2021.09.22 |
Comments