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
|
2743 Discussions
|
Please Login in order to post a comment
This is my solution using Python3
if name == 'main': N = int(input()) l=[] for i in range(N): command=input().split() if command[0]=="insert": l.insert(int(command[1]),int(command[2])) 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()
n = int(input()) list = [] for numb in range(n): func = (input().split()) if len(func) > 1: func[1] = int(func[1]) if len(func) > 2: func[2] = int(func[2]) if func[0] == 'insert': list.insert(func[1], func[2]) elif func[0] == 'print': print(list) elif func[0] == 'remove': list.remove(func[1]) elif func[0] == 'append': list.append(func[1]) elif func[0] == 'sort': list.sort() elif func[0] == 'pop': list.pop() elif func[0] == 'reverse': list.reverse()