Python deque() function of Collections module

Author: Al-mamun Sarkar Date: 2020-03-26 13:21:10

Python deque() function of Collections module. Deque is a double-ended queue. The following code shows how to solve the HackerRank Collections.deque() Python collections problem

Code:

from collections import deque

d = deque()

for _ in range(int(input())):
    cmd, *args = input().split()
    getattr(d, cmd)(*args)
[print(x, end=' ') for x in d]

 

Test Input:

6
append 1
append 2
append 3
appendleft 4
pop
popleft

Test Output:

1 2