Collections.deque()

  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    from collections import deque
    
    n = int(input())
    empty_queue = deque()
    
    for i in range(n):
        m = input().split()
    
        if m[0] == 'append':
            empty_queue.append(m[1])
        if m[0] == 'pop':
            empty_queue.pop()
        if m[0] == 'appendleft':
            empty_queue.appendleft(m[1])
        if m[0] == 'popleft':
            empty_queue.popleft()
    
    print(*empty_queue)