Collections.deque()

  • + 0 comments

    from collections import deque n = int(input()) d = deque() for _ in range(n): x =input().split() m = x[0] try: v= x[1] except Exception as e: pass

    match m:
        case "append":
            d.append(v)
        case "appendleft":
            d.appendleft(v)
        case "pop":
            d.pop()
        case "popleft":
            d.popleft()
        case _:
            print(-1)
    

    #

    print(*d)