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
Post a Comment