=====Function Descriptions=====
collections.deque()
A deque is a double-ended queue. It can be used to add or remove elements from both ends.

Deques support thread safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction.

Example
Code
>>> from collections import deque
>>> d = deque()
>>> d.append(1)
>>> print d
deque([1])
>>> d.appendleft(2)
>>> print d
deque([2, 1])
>>> d.clear()
>>> print d
deque([])
>>> d.extend('1')
>>> print d
deque(['1'])
>>> d.extendleft('234')
>>> print d
deque(['4', '3', '2', '1'])
>>> d.count('1')
1
>>> d.pop()
'1'
>>> print d
deque(['4', '3', '2'])
>>> d.popleft()
'4'
>>> print d
deque(['3', '2'])
>>> d.extend('7896')
>>> print d
deque(['3', '2', '7', '8', '9', '6'])
>>> d.remove('2')
>>> print d
deque(['3', '7', '8', '9', '6'])
>>> d.reverse()
>>> print d
deque(['6', '9', '8', '7', '3'])
>>> d.rotate(3)
>>> print d
deque(['8', '7', '3', '6', '9'])

=====Problem Statement=====
Perform append, pop, popleft and appendleft methods on an empty deque d.

=====Input Format=====
The first line contains an integer N, the number of operations.
The next N lines contains the space separated names of methods and their values.

=====Constraints=====
0<N≤100

=====Output Format=====
Print the space separated elements of deque d.

Difficulty: introductory

Starter code:

# Enter your code here. Read input from STDIN. Print output to STDOUT

Solutions:
import collections
n = int(input())
d = collections.deque()
for i in range(n):
    cmd = list(input().strip().split())
    opt = cmd[0]
    if opt == 'pop':
        d.pop()
    elif opt == 'popleft':
        d.popleft()
    elif opt == 'append':
        d.append(int(cmd[1]))
    elif opt == 'appendleft':
        d.appendleft(int(cmd[1]))
for i in d:
    print(i,end=' ')

        


#!/usr/bin/env python3

from collections import deque

def __starting_point():
    num = int(input().strip())
    deq = deque()
    
    for _ in range(num):
        args = input().strip().split()
        
        if args[0] == 'append':
            deq.append(args[1])
        elif args[0] == 'appendleft':
            deq.appendleft(args[1])
        elif args[0] == 'pop':
            deq.pop()
        elif args[0] == 'popleft':
            deq.popleft()
            
    out = []
    for el in deq:
        out.append(el)
            
    print(" ".join(map(str, out)))
__starting_point()