You are viewing a single comment's thread. Return to all comments →
length_of_list=int(input()) list_of_commands=[] final_list=[] for i in range(length_of_list): list_of_commands=list(input().split(" ")) if list_of_commands[0]=="insert": final_list.insert(int(list_of_commands[1]),int(list_of_commands[2])) elif list_of_commands[0]=="print": print(final_list) elif list_of_commands[0]=="remove": final_list.remove(int(list_of_commands[1])) elif list_of_commands[0]=="append": final_list.append(int(list_of_commands[1])) elif list_of_commands[0]=="sort": final_list.sort() elif list_of_commands[0]=="pop": final_list.pop() elif list_of_commands[0]=="reverse": final_list.reverse() else: pass
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Lists
You are viewing a single comment's thread. Return to all comments →
length_of_list=int(input()) list_of_commands=[] final_list=[] for i in range(length_of_list): list_of_commands=list(input().split(" ")) if list_of_commands[0]=="insert": final_list.insert(int(list_of_commands[1]),int(list_of_commands[2])) elif list_of_commands[0]=="print": print(final_list) elif list_of_commands[0]=="remove": final_list.remove(int(list_of_commands[1])) elif list_of_commands[0]=="append": final_list.append(int(list_of_commands[1])) elif list_of_commands[0]=="sort": final_list.sort() elif list_of_commands[0]=="pop": final_list.pop() elif list_of_commands[0]=="reverse": final_list.reverse() else: pass