There are 5 students in this class whose names and grades are assembled to build the following list:
students = [['Harry', 37.21], ['Berry', 37.21], ['Tina', 37.2], ['Akriti', 41], ['Harsh', 39]]
The lowest grade of 37.2 belongs to Tina. The second lowest grade of 37.21 belongs to both Harry and Berry, so we order their names alphabetically and print each name on a new line.
Solution:
min_score = min(students, key=lambda student: student[1])
second_min_score = min(students, key=lambda student: student[1] > min_score[1])
result = []
for record in records:
if record[1] == second_min_score[1]:
result.append(record[0])
result = sorted(result)
for res in result:
print(res)
second_min expected: ['Harry',37.21]
second_min coming: ['Tina', 37.2]
second_min_score = min(students, key=lambda student: student[1] > min_score[1])
Here I am trying to filter the nested list data having marks greater than the minimum to find the value of second minimum, but it doesn't seem to be working as expected, anyone can please explain the issue here. I am a newbie to python and it seems I didn't grasp the concept of lambda function correctly. I appreciate your help :)