n=int(input())
num=[]
for i in range(0,n):
op=input().split() #Take multiple input as a list by split(). 1st input is op[0],2nd is op[1] and 3rd input is op[2]
if len(op)==2:
element=int(op[1])
elif len(op)==3:
index = int(op[1])
element=int(op[2])
if op[0]=="insert":
num.insert(index,element)
#print(num)
elif op[0]=="append":
num.append(element)
#print(num)
elif op[0]=="print":
print(num)
elif op[0]=="remove":
num.remove(element)
#print(num)
elif op[0]=="reverse":
num.reverse()
#print(num)
elif op[0]=="pop":
num.pop()
#print(num)
elif op[0]=="sort":
num.sort()
#print(num)
Input :
12 insert 0 5 insert 1 10 insert 0 6 print remove 6 append 9 append 1 sort print pop reverse print
Output
[6, 5, 10]
[1, 5, 9, 10]
[9, 5, 1]
0 comments:
Post a Comment