일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- join
- Stack
- Growth hacking
- Queue
- 완전탐색
- counter
- 프로그래머스
- sql
- cte
- Level2
- coding test
- programmers
- import re
- lv4
- 파이썬
- python
- level4
- coding
- 조합
- hackerrank
- 코테
- time complexity
- 코딩테스트
- tableau
- AARRR
- 코딩
- itertools
- mysql
- collections
- lambda
Archives
- Today
- Total
ror_coding
[Python] Stack, Queue (collections) (deque) 본문
728x90
from collections import deque
- Stack (스택)
- Queue (큐)
from collections import deque
q = deque([1,2,3], maxlen = 5) # 크기 고정.
# 추가.
q.append(4) # [1,2,3,4]
q.appendleft(0) # [0,1,2,3,4]
# 제거 ( = 쓰면 제거된 값을 반환)
q.pop() # [0,1,2,3]
q.popleft() # [1,2,3]
# 확장
q.extend([4,5]) # [1,2,3] => [1,2,3,4,5]
q.extendleft([4,5]) # [1,2,3] => [5,4,1,2,3]
# 회전
q.rotate(1) # [1,2,3] => [3,1,2]
728x90
'Coding Test > Python' 카테고리의 다른 글
[Programmers] 피로도 - 87946 (3) | 2024.12.04 |
---|---|
[Programmers] 의상 - 42578 (2) | 2024.12.02 |
[Programmers] H-Index - 42747 (0) | 2024.12.02 |
[Programmers] n^2 배열 자르기 - 87390 (0) | 2024.11.01 |
[Programmers] 연속 부분 수열 합의 개수 - 131701 (0) | 2024.11.01 |