You are viewing a single comment's thread. Return to all comments →
i'm getting error in test cases 2 and 3 please help
n = int(input()) students = [] for i in range(n): name = input() grade = float(input()) students.append([name, grade])
students.sort(key=lambda x: x[1])
students.sort(key=lambda x: x[0])
second_lowest_grade = sorted([s[1] for s in students])[1]
for student in students: if student[1] == second_lowest_grade: print(student[0])
Seems like cookies are disabled on this browser, please enable them to open this website
Nested Lists
You are viewing a single comment's thread. Return to all comments →
i'm getting error in test cases 2 and 3 please help
n = int(input()) students = [] for i in range(n): name = input() grade = float(input()) students.append([name, grade])
sort the list based on grades
students.sort(key=lambda x: x[1])
sort the list of students based on their names
students.sort(key=lambda x: x[0])
find the second lowest grade
[1] at end is used to access the second element of the nested list
second_lowest_grade = sorted([s[1] for s in students])[1]
print names of students with the second lowest grade
for student in students: if student[1] == second_lowest_grade: print(student[0])