Collections.deque()

Sort by

recency

|

640 Discussions

|

  • + 0 comments

    from collections import deque n=int(input()) d=deque() for i in range(n): s=input().split(" ") if s[0]=="append": d.append(int(s[1])) elif s[0]=="appendleft": d.appendleft(int(s[1])) elif s[0]=="clear": d.clear() elif s[0]=="count": d.count(int(s[1])) elif s[0]=="extend": d.extend(int(s[1])) elif s[0]=="extendleft": d.extendleft(int(s[1])) elif s[0]=="pop": d.pop() elif s[0]=="popleft": d.popleft() elif s[0]=="remove": d.remove(int(s[1])) elif s[0]=="reverse": d.reverse() elif s[0]=="rotate": d.rotate(int(s[1])) print(*d)

  • + 0 comments
    from collections import deque
    
    d = deque()
    for _ in range(int(input())):
        func_arg = input().split()
        func = getattr(d, func_arg[0])
        if len(func_arg) == 1:
            func()
        else:
            func(func_arg[1])
    print(" ".join(d))
    
  • + 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)