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.
N = int(input())
list1=[]
for i in range(N):
cmd=input().split()
command=cmd[0]
if len(cmd)>1:
index=int(cmd[1])
if len(cmd)>2:
number=int(cmd[2])
if command=='insert':
list1.insert(index,number)
if command=='append':
list1.append(index)
elif command=='remove':
list1.remove(index)
if command=='print':
print(list1)
elif command=='pop':
list1.pop()
elif command=='reverse':
list1.reverse()
elif command=='sort':
list1.sort()
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 →
Here is mine
N = int(input()) list1=[] for i in range(N): cmd=input().split() command=cmd[0] if len(cmd)>1: index=int(cmd[1]) if len(cmd)>2: number=int(cmd[2]) if command=='insert': list1.insert(index,number) if command=='append': list1.append(index) elif command=='remove': list1.remove(index) if command=='print': print(list1) elif command=='pop': list1.pop() elif command=='reverse': list1.reverse() elif command=='sort': list1.sort()