Collections.deque()

Sort by

recency

|

651 Discussions

|

  • + 0 comments
    from collections import deque
    n = int(input())
    
    d = deque()
    for _ in range(n):
        text = input().rstrip().split()
        if len(text) > 1:
            opr, val = text
            getattr(d, opr)(int(val))
        else:
            getattr(d, text[0])()
    print(*d)
    
  • + 0 comments

    from collections import deque n = int(input()) d = deque()

    for _ in range(n): command = input().strip().split() method = getattr(d,command[0]) if len(command)==2: method(command[1]) else: method() for i in d: print(i,end=' ')

  • + 0 comments

    from collections import deque n = int(input()) d = deque()

    for _ in range(n): command = input().strip().split() method = getattr(d,command[0]) if len(command)==2: method(command[1]) else: method() for i in d: print(i,end=' ')

  • + 0 comments
    from collections import deque
    
    N = int(input())
    d = deque()
    
    for _ in range(N):
        commands = list(map(str,input().strip().split()))
        
        if commands[0] == 'append':
            d.append(int(commands[1]))
        elif commands[0] == 'appendleft':
            d.appendleft(int(commands[1]))
        elif commands[0] == 'extend':
            d.extend(int(commands[1]))
        elif commands[0] == 'extendleft':
            d.extendleft(int(commands[1]))
        elif commands[0] == 'pop':
            d.pop()
        elif commands[0] == 'popleft':
            d.popleft()
            
    
    print(" ".join(map(str, list(d))))
    
  • + 0 comments
    d=deque()
    for _ in range(int(input())):
        l= input().split()
        (getattr(d, l[0])())if len(l)==1 else (getattr(d, l[0])(l[1]))
    print(' '.join(d))