Sort by

recency

|

2914 Discussions

|

  • + 0 comments
    N = int(input())
    l = []      
    
    def performOperation(cmdList):
        match cmdList[0]:
            case 'insert': l.insert(int(cmdList[1]),int(cmdList[2]))                            
            case 'append': l.append(int(cmdList[1]))
            case 'remove': l.remove(int(cmdList[1]))
            case 'sort': l.sort()
            case 'pop': l.pop()
            case 'reverse': l.reverse()
            case 'print': print(l)
            case _: return
    
    for i in range(N):
        cmd = input()        
        performOperation(cmd.split(" "))
    
  • + 0 comments

    N=int(input()) mylist = [] for i in range(N): command = input().split()

    if command[0] == "insert":
        mylist.insert(int(command[1]), int(command[2]))
    
    elif command[0] == "print":
        print(mylist)
    
    elif command[0] == "remove":
        mylist.remove(int(command[1]))
    
    elif command[0] == "append":
        mylist.append(int(command[1]))
    
    elif command[0] == "sort":
        mylist.sort()
    
    elif command[0] == "pop":
        mylist.pop()
    
    elif command[0] == "reverse":
        mylist.reverse()
    
  • + 0 comments
    N = int(input())
    out = []
    for _ in range(N):
        parts = input().split()
        cmd = parts[0]
        args = list(map(int,parts[1:]))
    
        if cmd == 'print':
            print(out)
        else:
            getattr(out,cmd)(*args)
    
  • + 0 comments

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

    new_list = []

    for i in range (N): command = input().split() if command[0] == "append": new_list.append(int(command[1])) elif command[0] == "insert": new_list.insert(int(command[1]), int(command[2])) elif command[0] == "remove": new_list.remove(int(command[1])) elif command[0] == "sort": new_list.sort() elif command[0] == "pop": new_list.pop() elif command[0] == "reverse": new_list.reverse() elif command[0] == "print": print(new_list)

  • + 0 comments

    if name == 'main':

    N = int(input())
    lst = []
    for i in range(N):
        lst.append(input())
    out = []
    for i in range(len(lst)):
    
    
        command = str(lst[i]).split()
    
        if command[0] == 'insert':
            out.insert(int(command[1]), int(command[2]))
    
        elif command[0] == 'print':
            print(out)
    
        elif command[0] == 'remove' and int(command[1]) in out:
            out.remove(int(command[1]))
    
        elif command[0] == 'append':
            out.append(int(command[1]))
    
        elif command[0] == 'sort':
            out.sort()
    
        elif command[0] == 'pop' and len(out) > 0:
            out.pop()
    
        elif command[0] == 'reverse':
            out.reverse()