You are viewing a single comment's thread. Return to all comments →
students = [['Harry', 37.21], ['Berry', 37.21], ['Tina', 37.2], ['Akriti', 41], ['Harsh', 39]]
grades = sorted(set(score for name, score in students)) # Remove duplicates and sort second_lowest_grade = grades[1]
students_with_second_lowest_grade = [name for name, score in students if score == second_lowest_grade]
students_with_second_lowest_grade.sort()
for name in students_with_second_lowest_grade: print(name) 1.
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 →
Step 1: Create a nested list of student names and grades
students = [['Harry', 37.21], ['Berry', 37.21], ['Tina', 37.2], ['Akriti', 41], ['Harsh', 39]]
Step 2: Find the second lowest grade
grades = sorted(set(score for name, score in students)) # Remove duplicates and sort second_lowest_grade = grades[1]
Step 3: Collect names of students with the second lowest grade
students_with_second_lowest_grade = [name for name, score in students if score == second_lowest_grade]
Step 4: Sort the names alphabetically
students_with_second_lowest_grade.sort()
Step 5: Print each name on a new line
for name in students_with_second_lowest_grade: print(name) 1.