Skip to content

Instantly share code, notes, and snippets.

@ZhouYang1993
Created September 11, 2022 17:18
Show Gist options
  • Save ZhouYang1993/4760cecb09227de4cd3113bac0309144 to your computer and use it in GitHub Desktop.
Save ZhouYang1993/4760cecb09227de4cd3113bac0309144 to your computer and use it in GitHub Desktop.
deque in Python
from collections import deque
dq1=deque([1,2,3,4,5])
print(dq1)
# deque([1, 2, 3, 4, 5])
dq1.popleft()
print(dq1)
# deque([2, 3, 4, 5])
dq1.appendleft(9)
print(dq1)
# deque([9, 2, 3, 4, 5])
dq1.pop()
print(dq1)
# deque([9, 2, 3, 4])
dq1.append(8)
print(dq1)
# deque([9, 2, 3, 4, 8])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment