Nested Lists | HackerRank
In a classroom of N students, find the student with the second lowest grade.
www.hackerrank.com
Goal
Given the names and grades for each student in a class of N students, store them in a nested list and print the name(s) of any student(s) having the second lowest grade.
Solution
I use two lists to solve this problem. One list is for student name and score. The other list is only for score.
So, we need to sort score list and then find second lowest score.
After then, we sort student by name and find students which have second lowest score and print them alphabetically
# Nested Lists
if __name__ == '__main__':
students = []
scores = []
for _ in range(int(input())):
name = input()
score = float(input())
students.append([name, score])
scores.append(score)
scores.sort()
mini = scores[0]
second_min = 0
students.sort()
for score in scores:
if score != mini:
second_min = score
break
for student in students:
if student[1] == second_min:
print(student[0])'software Engineering > (Python)HackerRank' 카테고리의 다른 글
| [Python] HackerRank - Lists (0) | 2023.02.02 |
|---|---|
| [Python] HackerRank - Finding the percentage (0) | 2023.02.01 |
| [Python] HackerRank - Find the Runner-Up Score! (0) | 2023.01.29 |
| [Python] HackerRank -List Comprehensions (0) | 2023.01.28 |
| [Python] HackerRank - Print Function (0) | 2023.01.27 |