Collections.deque()

  • + 0 comments
    from collections import deque
    n = int(input())
    d = deque()
    for n in range(n):
        cmd = input().split()
        operation = cmd[0]
        if operation == "append":
            d.append(int(cmd[1]))
        elif operation == "appendleft":
            d.appendleft(int(cmd[1]))
        elif operation == "pop":
            d.pop()
        elif operation == "popleft":
            d.popleft()
            
    print(*d)