Sort by

recency

|

2784 Discussions

|

  • + 0 comments

    Here is my Code easy to understand:

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

    I dont know about coding, but i have a website https://mxplyerapks.info/, and i want to use this code in my website. is that possible

  • + 1 comment
    if __name__ == '__main__':
        mylist = []
        N = int(input().strip())
    
    for _ in range(N):
        cmd = input().strip().split()
    
        if cmd[0] == "insert":
            mylist.insert(int(cmd[1]), int(cmd[2]))
        elif cmd[0] == "print":
            print(mylist)
        elif cmd[0] == "remove":
            mylist.remove(int(cmd[1]))
        elif cmd[0] == "append":
            mylist.append(int(cmd[1]))
        elif cmd[0] == "sort":
            mylist.sort()
        elif cmd[0] == "pop":
            mylist.pop()
        elif cmd[0] == "reverse":
            mylist.reverse()
        else:
            print(f"Invalid command: {cmd[0]}")
    
  • + 1 comment
    action_list = {
            'insert': 'arr.insert({},{})',
            'print': 'print(arr)',
            'remove': 'arr.remove({})',
            'append': 'arr.append({})',
            'sort': 'arr.sort()',
            'pop': 'arr.pop()',
            'reverse': 'arr.reverse()',
    }
    arr = []
    
    for _ in range(int(input())):
            commands = input()
            command = commands.split()
            eval(action_list.get(command[0]).format(*command[1:]))
    
  • + 1 comment

    if name == 'main': N = int(input()) lst=[] for i in range(N): command = input().split() match(command[0].lower()): case "insert": lst.insert(int(command[1]), int(command[2]))

            case "print":
                print(lst)
    
            case "remove":
                lst.remove(int(command[1]))
    
            case "append":
                lst.append(int(command[1]))
    
            case "sort":
                lst.sort()
    
            case "pop":
                lst.pop()
    
            case "reverse":
                lst.reverse()
    
            case _:
                print("Invalid Command")