Sort by

recency

|

2846 Discussions

|

  • + 0 comments

    if name == 'main': N = int(input()) my_list=[] for _ in range(N): action=input().split() match action: case ["append", x]: my_list.append(int(x)) case ["insert",x,y]: my_list.insert(int(x),int(y)) case ["print"]: print(my_list) case ["remove",e]: my_list.remove(int(e)) case ["sort"]: my_list.sort() case ["pop"]: my_list.pop() case ["reverse"]: my_list.reverse()

  • + 0 comments

    `if name == "main": N = int(input())

    thislist = []
    
    commands = {
        "insert": lambda x: thislist.insert(x[0], x[1]),
        "print": lambda x: print(thislist),
        "remove": lambda x: thislist.remove(x[0]),
        "append": lambda x: thislist.append(x[0]),
        "sort": lambda x: thislist.sort(),
        "pop": lambda x: thislist.pop(),
        "reverse": lambda x: thislist.reverse(),
    }
    
    for _ in range(N):
        command = input().strip().split()
        cmd, args = command[0], list(map(int, command[1:]))
    
        if cmd in commands:
            commands[cmd](args)
    

  • + 0 comments
    if __name__ == '__main__':
        N = int(input())
        list=[]
        for _ in range (N):
            cmd=input().split()
            if cmd[0]=="insert":
                list.insert( int(cmd[1]), int(cmd[2]) )
            elif cmd[0]=="print":
                print(list)
            elif cmd[0]=="append":
                list.append(int(cmd[1]))
            elif cmd[0]=="remove":
                list.remove(int(cmd[1]))
            elif cmd[0]=="sort":
                list.sort()
            elif cmd[0]=="pop":
                list.pop()
            elif cmd[0]=="reverse":
                list.reverse()
    
  • + 0 comments
    inputAmount = int(input())
    list = []
    i = 0
    while i < inputAmount:
        i = i + 1
        newInput = str(input())
        if "insert" in newInput:
            list.insert(int(newInput.split(" ", 2)[1]), int(newInput.split(" ", 2)[2]))
        elif "print" in newInput:
            print(list)
        elif "remove" in newInput:
            list.remove(int(newInput.split(" ", 1)[1]))
        elif "append" in newInput:
            list.append(int(newInput.split(" ", 1)[1]))
        elif "sort" in newInput:
            list.sort()
        elif "pop" in newInput:
            list.pop()
        elif "reverse" in newInput:
            list.reverse()
        
    
  • + 0 comments

    if name == 'main': N = int(input()) # Number of commands my_list = [] # Initialize empty list

    for _ in range(N):
        command = input().strip().split()
        operation = command[0]
    
        if operation == 'insert':
            i = int(command[1])
            e = int(command[2])
            my_list.insert(i, e)
        elif operation == 'print':
            print(my_list)
        elif operation == 'remove':
            e = int(command[1])
            my_list.remove(e)
        elif operation == 'append':
            e = int(command[1])
            my_list.append(e)
        elif operation == 'sort':
            my_list.sort()
        elif operation == 'pop':
            my_list.pop()
        elif operation == 'reverse':
            my_list.reverse()