Nested List (hackerRank)
Given the names and grades for each student in a class of students, store them in a nested list and print the name(s) of any student(s) having the second lowest grade.
Note: If there are multiple students with the second lowest grade, order their names alphabetically and print each name on a new line.
Example
The ordered list of scores is , so the second lowest score is . There are two students with that score: . Ordered alphabetically, the names are printed as:
alpha beta
## Solution:--
list_of_students=[]second_lowest_names=[]scores=set()for _ in range(int(input())):name=input()score=float(input())list_of_students.append([name,score])scores.add(score)second_lowest_score=sorted(scores)[1]for name,score in list_of_students:if score==second_lowest_score:second_lowest_names.append(name)for name in sorted(second_lowest_names):print(name)
Comments
Post a Comment