-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.py
More file actions
29 lines (29 loc) · 965 Bytes
/
list.py
File metadata and controls
29 lines (29 loc) · 965 Bytes
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
def list_operation(command):
global List
if command[0:6] == 'insert':
num = list(filter(lambda x: x.isdigit(), command.split()))
index = int(num[0])
value = int(num[1])
List.insert(index,value)
elif command[0:6] == 'append':
value = int(filter(lambda x: x.isdigit(), command.split()))
List.append(value)
elif command[0:6] == 'remove':
value = int(filter(lambda x: x.isdigit(), command.split()))
List.remove(value)
if __name__ == '__main__':
N = int(input())
List = []
for i in range (0,N):
command = input()
command_list = ["append","insert","remove"]
if command[0:6] in command_list:
list_operation(command)
elif command == 'print':
print(List)
elif command == 'sort':
List.sort()
elif command == 'pop':
List.pop()
elif command == 'reverse':
List.reverse()