Sort by

recency

|

2866 Discussions

|

  • + 0 comments
    if __name__ == '__main__':
        N = int(input())
        res = []
        for i in range(N):
            row = input().split()
            
            match row[0]:
                case "append":
                    res.append(int(row[1]))
                case "reverse":
                    res.reverse()
                case "sort":
                    res = sorted(res)
                case "insert":
                    res.insert(int(row[1]), int(row[2]))
                case "print":
                    print(res)
                case "remove":
                    res.remove(int(row[1]))
                case "pop":
                    res.pop()
                    
    
  • + 0 comments
    N = int(input())
        List = []
        
        for i in range(N):
            command = input().split()
    
            if command[0] == "insert":
                List.insert(int(command[1]),int(command[2]))
            elif command[0] == "print":
                print(List)
            elif command[0] == "remove":
                List.remove(int(command[1]))
            elif command[0] == "append":
                List.append(int(command[1]))
            elif command[0] == "sort":
                List.sort()
            elif command[0] == "pop":
                List.pop()
            elif command[0] == "reverse":
                List.reverse()
            else:
                exit()
                
    
  • + 0 comments

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

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

    for noobs like me, who do not care about chatgpt or time complexities

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

    lis = [] for _ in range(N): ip = input().split(" ") j = ip[0]

    if ip[0] == "insert":
        lis.insert(int(ip[1]), int(ip[2]))
    elif ip[0] == "print":
        print(lis)
    elif ip[0] == "remove":
        lis.remove(int(ip[1]))
    elif j == "append":
        lis.append(int(ip[1]))
    elif j == "sort":
        lis.sort()
    elif j == "pop":
        lis.pop(-1)
    elif j == "reverse":
        lis.reverse()
    else:
        print("Invalid")
    
  • + 0 comments
    if __name__ == '__main__':
        N = int(input())
        
    l = []``
    
    for i in range(N):
        c = input()
        co = c.split()
        if co[0] == 'insert':
            l.insert(int(co[1]), int(co[2]))
        elif co[0] == 'print':
            print(l)
        elif co[0] == 'remove':
            l.remove(int(co[1]))
        elif co[0] == 'append':
            l.append(int(co[1]))
        elif co[0] == 'sort':
            l.sort()
        elif co[0] == 'pop':
    
        l.pop()
    elif co[0] == 'reverse':
        l.reverse()