We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
if name == 'main':
students=[]
for _ in range(int(input())):
name = input()
score = float(input())
students.append([name,score])
sorted_students = sorted(students, key=lambda x: x[1])
# Finding the second lowest grade
second_lowest_grade = sorted(set(student[1] for student in students))[1]
# Extracting names of students with the second lowest grade
second_lowest_students = [student[0] for student in sorted_students if student[1] == second_lowest_grade]
# Sorting the names alphabetically
second_lowest_students.sort()
# Printing the names of students with the second lowest grade
for student in second_lowest_students:
print(student)
# Printing the names of students with the second lowest grade
for student in second_lowest_students:
print(student)
This solution will break with the following test case:
[['a', 1.0], ['b', 1.0], ['c', 2.0], ['d', 2.0]]
Both a and b have the lowest grade. second_lowest_grade = sorted(set(student[1] for student in students))[1]
will select [b. 1.0] which is the lowest grade still
Nested Lists
You are viewing a single comment's thread. Return to all comments →
if name == 'main': students=[] for _ in range(int(input())): name = input() score = float(input()) students.append([name,score])
This solution will break with the following test case:
[['a', 1.0], ['b', 1.0], ['c', 2.0], ['d', 2.0]]
Both a and b have the lowest grade. second_lowest_grade = sorted(set(student[1] for student in students))[1] will select [b. 1.0] which is the lowest grade still
it will not because it is a set