We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
if__name__=='__main__':anslist=[]#Whattheoutputwillgive#inputtedList=[] #How we split the inputsN=int(input())foriinrange(N):inputedcommand=str(input())inputtedList=inputedcommand.split(' ')ifinputedcommand.count('append')==1:inputtedList=inputtedList[1:]foriininputtedList:anslist.append(int(i))ifinputedcommand.count('insert')==1:inputtedList=inputtedList[1:]#Skipstheinputedcommandsinceposition=int(inputtedList[0])#Getsfirstnumberoninsertinputdigit=int(inputtedList[1])#Getssecondnumberoninsertinputanslist.insert(position,digit)ifinputedcommand.count('print')==1:inputtedList=inputtedList[1:]print(anslist)ifinputedcommand.count('remove')==1:inputtedList=inputtedList[1:]anslist.remove(int(inputtedList[0]))ifinputedcommand.count('sort')==1:inputtedList=inputtedList[1:]anslist.sort()ifinputedcommand.count('pop')==1:inputtedList=inputtedList[1:]anslist.pop()ifinputedcommand.count('reverse')==1:inputtedList=inputtedList[1:]anslist.reverse()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lists
You are viewing a single comment's thread. Return to all comments →