-
deque
list-like container with fast appends and pops on either end>>> from collections import deque >>> >>> >>> d = deque("abc") >>> d deque(['a', 'b', 'c']) >>> d = deque([11,22,33]) >>> d deque([11, 22, 33]) >>> d = deque("abc") >>> d deque(['a', 'b', 'c']) >>> d.append('e') >>> d deque(['a', 'b', 'c', 'e']) >>> d.rotate(1) >>> d deque(['e', 'a', 'b', 'c']) >>> d.rotate(-2) >>> d deque(['b', 'c', 'e', 'a']) >>> d.append("ghi") >>> d deque(['b', 'c', 'e', 'a', 'ghi']) >>> d.extend("jkl") >>> d deque(['b', 'c', 'e', 'a', 'ghi', 'j', 'k', 'l']) >>> d.pop() 'l' >>> d.popleft() 'b' >>> d deque(['c', 'e', 'a', 'ghi', 'j', 'k']) >>> d[0] 'c' >>> d[-1] 'k' >>>
'Python' 카테고리의 다른 글
Python - exe 파일 만들기 (0) 2020.09.09 Python - itertools (0) 2020.09.08 Python - namedtuple (0) 2020.09.08 Python - Counter (0) 2020.09.08 Python - Time Complexity (0) 2020.09.07 Python - reversed 클래스 함수 (0) 2020.09.07 Python - generator expression (0) 2020.09.07 Python - 함수 인수 (0) 2020.09.06