In this HackerRank Collections.deque() problem solution we need to perform append, pop, popleft and appendleft methods on an empty deque d.

HackerRank Collections.deque() in python problem solution

HackerRank Collections.deque() in python problem solution

# Enter your code here. Read input from STDIN. Print output to STDOUT
from collections import deque
d = deque()
N = int(raw_input())
for i in range(N):
    Input = raw_input().split()
    if Input[0] == 'append':
        d.append(Input[1])
    elif Input[0] == 'appendleft':
        d.appendleft(Input[1])
    elif Input[0] == 'pop':
        d.pop()
    elif Input[0] == 'popleft':
        d.popleft()
print ' '.join(d)