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.
- Prepare
- Python
- Basic Data Types
- Lists
- Discussions
Lists
Lists
Sort by
recency
|
2830 Discussions
|
Please Login in order to post a comment
if name == 'main': N = int(input()) num=[] for _ in range(N): cp=input().split() c=cp[0] if c=="insert": idx=int(cp[1]) val=int(cp[2]) num.insert(idx,val) elif c=="append": val=int(cp[1]) num.append(val) elif c=="remove": val=int(cp[1]) num.remove(val) elif c=="print": print(num) elif c=="sort": num.sort() elif c=="pop": num.pop() elif c=="reverse": num.reverse()
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
if name == 'main': N = int(input()) my_list = [] for _ in range(N): inp=input().split() if(inp[0] == 'insert'): my_list.insert(int(inp[1]) , int(inp[2])) elif(inp[0] == 'print'): print(my_list) elif(inp[0] == 'remove'): my_list.remove(int(inp[1])) elif(inp[0] == 'append'): my_list.append(int(inp[1])) elif(inp[0] == 'sort'): my_list.sort() elif(inp[0] == 'pop'): my_list.pop() elif(inp[0] == 'reverse'): my_list.reverse()