Sort by

recency

|

2881 Discussions

|

  • + 0 comments

    if name == 'main': N = int(input()) # Read the number of commands lst = [] # Initialize the list

    for _ in range(N):
        command = input().strip().split()  # Read and split command
        cmd = command[0]
    
        if cmd == 'insert':
            lst.insert(int(command[1]), int(command[2]))
        elif cmd == 'print':
            print(lst)
        elif cmd == 'remove':
            lst.remove(int(command[1]))
        elif cmd == 'append':
            lst.append(int(command[1]))
        elif cmd == 'sort':
            lst.sort()
        elif cmd == 'pop':
            lst.pop()
        elif cmd == 'reverse':
            lst.reverse()
    
  • + 0 comments

    if name == 'main': N = int(input()) commands_marks ={} res = [] for _ in range(N): commands , *line = input().split() indexs = list(map(int,line)) commands_marks[commands] = indexs if commands == 'insert': res.insert(indexs[0],indexs[1]) elif commands == 'print': print(res) elif commands=='append': res.append(indexs[0]) elif commands == 'sort': res.sort() elif commands =='pop': res.pop() elif commands == 'reverse': res.reverse() elif commands =='remove': res.remove(indexs[0])

  • + 0 comments

    if name == 'main': lst = [] N = int(input()) for i in range(N): cho = input().lower() ch = cho.split() match ch[0]: case "insert": lst.insert(int(ch[1]), int(ch[2])) case "print": print(lst) case "remove": lst.remove(int(ch[1])) case "append": lst.append(int(ch[1])) case "sort": lst.sort() case "pop": lst.pop() case "reverse": lst.reverse() case _: print("INVALID CHOICE!")

  • + 0 comments

    if name == 'main': lst = [] N = int(input()) for i in range(N): cho = input().lower() ch = cho.split() match ch[0]: case "insert": lst.insert(int(ch[1]), int(ch[2])) case "print": print(lst) case "remove": lst.remove(int(ch[1])) case "append": lst.append(int(ch[1])) case "sort": lst.sort() case "pop": lst.pop() case "reverse": lst.reverse() case _: print("INVALID CHOICE!")

  • + 0 comments

    if name == 'main': N = int(input()) l=list() for op in range(N): inputs=input().split() operation=inputs[0] if operation=='insert': l.insert(int(inputs[1]),int(inputs[2])) elif operation=='pop' or operation=='reverse' or operation=='sort': eval(f"l.{operation}()") elif operation=='print': print(l) else: method=f"l.{operation}({int(inputs[1])})" eval(method)