Collections.deque()

  • + 0 comments

    from collections import deque

    if name == 'main': N = int(input()) d = deque()

    for _ in range(N):
    
        command = input().split()
        operation = command[0]
    
    
        if operation == "append":
            d.append(int(command[1]))
        elif operation == "appendleft":
            d.appendleft(int(command[1]))
        elif operation == "pop":
            d.pop()
        elif operation == "popleft":
            d.popleft()
    
    
    print(" ".join(map(str, d)))