You are viewing a single comment's thread. Return to all comments →
n = int(input())
students = []
for _ in range(n): name = input() grade = float(input()) students.append([name, grade])
grades = sorted(set([student[1] for student in students]))
second_lowest_grade = grades[1]
second_lowest_students = [student[0] for student in students if student[1] == second_lowest_grade]
second_lowest_students.sort()
for student in second_lowest_students: print(student)
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 →
Read the number of students
n = int(input())
Initialize an empty list to store students' name and grade pairs
students = []
Read the student data
for _ in range(n): name = input() grade = float(input()) students.append([name, grade])
Extract all the unique grades, sort them, and get the second lowest grade
grades = sorted(set([student[1] for student in students]))
Find the second lowest grade
second_lowest_grade = grades[1]
Find the names of students with the second lowest grade
second_lowest_students = [student[0] for student in students if student[1] == second_lowest_grade]
Sort the names alphabetically
second_lowest_students.sort()
Print the names
for student in second_lowest_students: print(student)