Python deque() function of Collections module

Python deque() function of Collections module

Instructor-svgAl-Mamun Sarkar
Mar 26 , 2020

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
  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram