Lists | HackerRank
Perform different list operations.
www.hackerrank.com
Goal
read different commands, operate commands and print the results.
Solution
you can create if statement to operate each command.
But important is to read the values after commands.
I use *line to read values.
# Lists
if __name__ == '__main__':
N = int(input())
results = []
for _ in range(N):
name, *line = input().split()
if name == "insert":
results.insert(int(line[0]), int(line[1]))
elif name == "append":
results.append(int(line[0]))
elif name == "sort":
results.sort()
elif name == "print":
print(results)
elif name == "pop":
results.pop()
elif name == "remove" :
results.remove(int(line[0]))
else: #name == reverse
results.reverse()
'software Engineering > (Python)HackerRank' 카테고리의 다른 글
[Python] HackerRank - String Split and Join (0) | 2023.02.07 |
---|---|
[Python] HackerRank - sWAP cASE (0) | 2023.02.03 |
[Python] HackerRank - Finding the percentage (0) | 2023.02.01 |
[Python] HackerRank - Nested Lists (0) | 2023.01.31 |
[Python] HackerRank - Find the Runner-Up Score! (0) | 2023.01.29 |