Skip to content

Commit d077c2f

Browse files
authored
Add files via upload
1 parent a30f057 commit d077c2f

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

Lists.py

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Consider a list (list = []). You can perform the following commands:
2+
3+
# insert i e: Insert integer at position .
4+
# print: Print the list.
5+
# remove e: Delete the first occurrence of integer .
6+
# append e: Insert integer at the end of the list.
7+
# sort: Sort the list.
8+
# pop: Pop the last element from the list.
9+
# reverse: Reverse the list.
10+
# Initialize your list and read in the value of followed by lines of commands where each command will be of the types listed above. Iterate through each command in order and perform the corresponding operation on your list.
11+
12+
# Input Format
13+
14+
# The first line contains an integer, , denoting the number of commands.
15+
# Each line of the subsequent lines contains one of the commands described above.
16+
17+
# Constraints
18+
19+
# The elements added to the list must be integers.
20+
# Output Format
21+
22+
# For each command of type print, print the list on a new line.
23+
24+
# Sample Input 0
25+
26+
# 12
27+
# insert 0 5
28+
# insert 1 10
29+
# insert 0 6
30+
# print
31+
# remove 6
32+
# append 9
33+
# append 1
34+
# sort
35+
# print
36+
# pop
37+
# reverse
38+
# print
39+
# Sample Output 0
40+
41+
# [6, 5, 10]
42+
# [1, 5, 9, 10]
43+
# [9, 5, 1]
44+
45+
46+
47+
48+
if __name__ == '__main__':
49+
N = int(input())
50+
51+
52+
list1 = []
53+
for i in range(N):
54+
stri = input().split()
55+
if(stri[0] == "print"):
56+
print(list1)
57+
elif(stri[0] == "sort"):
58+
list1.sort()
59+
elif(stri[0] == "pop"):
60+
list1.pop()
61+
elif(stri[0]=="insert"):
62+
list1.insert(int(stri[1]),int(stri[2]))
63+
elif(stri[0]=="remove"):
64+
list1.remove(int(stri[1]))
65+
elif(stri[0]=="append"):
66+
list1.append(int(stri[1]))
67+
elif(stri[0]=="reverse"):
68+
list1.reverse()
69+
70+
71+
72+
73+
74+
75+

0 commit comments

Comments
 (0)