• + 1 comment

    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)
    
    • + 1 comment

      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

      • + 0 comments

        it will not because it is a set