Sort by

recency

|

2767 Discussions

|

  • + 2 comments

    I felt very proud of my solution! I realized all the operations were already python list operations (except print) and tried a more elegent solution than the brute force I typically apply.

    if __name__ == '__main__':
        N = int(input())
        l = []
        for i in range(N):
            line = input().split(" ")
            oper = line[0]
            if oper == "print":
                print(l)
            else:
                args = line[1:]
                args = [(int)(n) for n in args]
                getattr(l, oper)(*args)
    
  • + 0 comments
    if __name__ == '__main__':
        anslist=[] #What the output will give
        #inputtedList=[] #How we split the inputs
        N = int(input())
        for i in range(N):
            inputedcommand=str(input())
            inputtedList=inputedcommand.split(' ')
            if inputedcommand.count('append')==1:
                inputtedList=inputtedList[1:]
                for i in inputtedList:
                    anslist.append(int(i))
            if inputedcommand.count('insert')==1:
                inputtedList=inputtedList[1:] #Skips the inputed command since 
                position=int(inputtedList[0]) #Gets first number on insert input
                digit=int(inputtedList[1]) #Gets second number on insert input
                anslist.insert(position,digit)
            if inputedcommand.count('print')==1:
                inputtedList=inputtedList[1:]
                print(anslist)
            if inputedcommand.count('remove')==1:
                inputtedList=inputtedList[1:]
                anslist.remove(int(inputtedList[0]))
            if inputedcommand.count('sort')==1:
                inputtedList=inputtedList[1:]
                anslist.sort()
            if inputedcommand.count('pop')==1:
                inputtedList=inputtedList[1:]
                anslist.pop()
            if inputedcommand.count('reverse')==1:
                inputtedList=inputtedList[1:]
                anslist.reverse()
    
  • + 0 comments

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

  • + 0 comments

    if name == 'main': N = int(input()) lst = []

    for _ in range(N):
        command = input().split()
        cmd = command[0]
    
        if cmd == "insert":
            index, value = int(command[1]), int(command[2])
            lst.insert(index, value)
        elif cmd == "print":
            print(lst)
        elif cmd == "remove":
            value = int(command[1])
            lst.remove(value)
        elif cmd == "append":
            value = int(command[1])
            lst.append(value)
        elif cmd == "sort":
            lst.sort()
        elif cmd == "pop":
            lst.pop()
        elif cmd == "reverse":
            lst.reverse()
    
  • + 0 comments
    if __name__ == '__main__':
        N = int(input())
        liste = []
        for i in range(N):
            command = input()
            critere = command.split(" ")[0]
            
            if critere == "insert":
                [i, e] = command.split(" ")[1:]
                liste.insert(int(i), int(e))
            elif critere == "print":
                print(liste)
            elif critere == "remove":
                liste.remove(int(command.split(" ")[1]))
            elif critere == "append":
                liste.append(int(command.split(" ")[1]))
            elif critere == "sort":
                liste.sort()
            elif critere == "pop":
                liste.pop()
            elif critere == "reverse":
                liste.reverse()