Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e705a89

Browse files
HahckerRank
1 parent f2b48e5 commit e705a89

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

‎Hackerrank-Python3/list.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
n = int(input())
2+
l = list()
3+
for i in range(n):
4+
x = input()
5+
if x.count(" ") == 2:
6+
command, pos, element = x.split(" ")
7+
if (command == "insert"):
8+
# print("inserting..")
9+
pos = int(pos)
10+
element = int(element)
11+
l.insert(pos, element)
12+
# print(l)
13+
14+
if x.count(" ") == 1:
15+
command, element = x.split(" ")
16+
element = int(element)
17+
if (command == "remove"):
18+
l.remove(element)
19+
# print("removed")
20+
elif (command == "append"):
21+
l.append(element)
22+
23+
else:
24+
command = x
25+
if (command == "print"):
26+
# print("printing..")
27+
print(l)
28+
elif (command == "sort"):
29+
l.sort()
30+
elif (command == "pop"):
31+
l.pop()
32+
elif (command == "reverse"):
33+
l.reverse()
34+
35+
36+
# Sample Input 0
37+
38+
# 12
39+
# insert 0 5
40+
# insert 1 10
41+
# insert 0 6
42+
# print
43+
# remove 6
44+
# append 9
45+
# append 1
46+
# sort
47+
# print
48+
# pop
49+
# reverse
50+
# print
51+
52+
# Sample Output
53+
54+
# [6, 5, 10]
55+
# [1, 5, 9, 10]
56+
# [9, 5, 1]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /