Please if anyone can explain me how this code works, it would be very helpful. Question :
Print the name(s) of any student(s) having the second lowest grade in. If there are multiple students, order their names alphabetically and print each one on a new line. There are students in this class whose names and grades are assembled to build the following list:
python students = [['Harry', 37.21], ['Berry', 37.21], ['Tina', 37.2], ['Akriti', 41], ['Harsh', 39]]
The lowest grade of belongs to Tina. The second lowest grade of belongs to both Harry and Berry, so we order their names alphabetically and print each name on a new line.
Answer
marksheet = []
for _ in range(0,int(input())):
marksheet.append([input(), float(input())])
second_highest = sorted(list(set([marks for name, marks in marksheet])))[1]
print('\n'.join([a for a,b in sorted(marksheet) if b == second_highest]))
Result :
Berry
Harry
Can anyone please explain how the second highest is calculated. I understand that set function splits the data into distinct values and removes duplicates but what is like marks for name, marks in marksheet I am confused as marks and name are not even mentioned any where. How this second highest works. THANKS IN ADVANCE