Collections.deque() HackersRank Solution

 from collections import deque

n = int(input())
L = deque()
for i in range(n):
    d = input().split()
    oper = d[0]
    
    if len(d)>1:
        val = d[1]
    if oper == 'append':
        L.append(val)
    elif oper == 'appendleft':
        L.appendleft(val)
    elif oper == 'pop':
        L.pop()
    elif oper == 'popleft':
        L.popleft()

print(*L)

Comments

Popular posts from this blog

Mean, Var, and Std in numpy HackerRank

Min and Max in numpy HackerRank