Collections.deque()

Sort by

recency

|

638 Discussions

|

  • + 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)))
    
  • + 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)

  • + 0 comments

    from collections import deque

    d=deque([]) n=int(input()) for _ in range(n): method,*args=input().split() if args: getattr(d,method)(*map(int,args)) else: getattr(d,method)() print(*d)

  • + 0 comments
    from collections import deque
    
    lst = deque([])
    
    for _ in range(int(input())):
        eval('lst.{0}({1})'.format(*input().split() + ['']))
        
    print(*lst)``
    
  • + 0 comments
    from collections import deque
     
    if __name__ == "__main__":
        n = int(input())
        d = deque()
        for i in range(n):
            temp =  input().split()
            if len(temp)>1:
                getattr(d,temp[0])(temp[1])
            else:
                getattr(d,temp[0])()
        print(' '.join(d))