-
Notifications
You must be signed in to change notification settings - Fork 5
/
Day12Lists.py
31 lines (28 loc) · 1.14 KB
/
Day12Lists.py
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
if __name__ == '__main__':
N = int(input())
list = []
for i in range(N):
args = input().strip().split(" ")
if args[0] == "append":
list.append(int(args[1]))
elif args[0] == "insert":
list.insert(int(args[1]), int(args[2]))
elif args[0] == "print":
print(list)
elif args[0] == "remove":
list.remove(int(args[1]))
elif args[0] == "sort":
list.sort()
elif args[0] == "pop":
list.pop()
elif args[0] == "reverse":
list.reverse()
# Consider a list (list = []). You can perform the following commands:
# insert i e: Insert integer at position .
# print: Print the list.
# remove e: Delete the first occurrence of integer .
# append e: Insert integer at the end of the list.
# sort: Sort the list.
# pop: Pop the last element from the list.
# reverse: Reverse the list.
# Initialize your list and read in the value of followed by lines of commands where each command will be of the 7 types listed above. Iterate through each command in order and perform the corresponding operation on your list.