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
|
2767 Discussions
|
Please Login in order to post a comment
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.
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()
if name == 'main': N = int(input()) lst = []