-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistmethods-problem.py
More file actions
37 lines (37 loc) · 1.21 KB
/
listmethods-problem.py
File metadata and controls
37 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
if __name__ == '__main__':
N = int(input())
array = []
temp_array = []
for testcases in range(N):
commands = input().split(' ')
if commands[0] == "append":
for i in range(len(commands)- 1):
i+=1
array.append(commands[i])
array[i-1] = int(array[i-1])
i-=1
for j in range(len(array)):
temp_array.append(array[j])
print(temp_array)
array.clear()
elif commands[0] == "pop":
temp_array.pop()
print(temp_array)
elif commands[0] == "remove":
commands[1] = int(commands[1])
temp_array.remove(commands[1])
print(temp_array)
elif commands[0] == "reverse":
temp_array.reverse()
print(temp_array)
elif commands[0] == "sort":
temp_array.sort()
elif commands[0] == "print":
print(temp_array)
elif commands[0] == "insert":
commands[1] = int(commands[1])
commands[2] = int(commands[2])
temp_array.insert(commands[1],commands[2])
print(temp_array)
else:
print("wrong commands")