• + 21 comments

    List comprehensions are so great!

    if __name__ == '__main__':
        a= []
        for _ in range(int(input())):
            name = input()
            score = float(input())
            a.append([score, name])
    
        a.sort()
        b = [i for i in a if i[0] != a[0][0]]
        c = [j for j in b if j[0] == b[0][0]]
        
        c.sort(key=lambda x: x[1])
        for i in range(len(c)):
            print(c[i][1])
    

    Explanation

    list a is simply a list of all the input data. It is sorted so that the lowest score is in the first index.

    list b uses a list comprehension to remove all instances of the lowest score from list a. The lowest remaining score in the resulting list (found in the first index since it will be the first value taken from the already-sorted list a) is the second-lowest score overall.

    list c then uses another list comprehension to trim down list b to only those scores that are equal to that second-lowest overall score.

    list c is now a nested list containing the scores and names of the students that will make up the output. It is sorted alphabetically according to student name by using a lambda expression which indicates to use the contents of the second index of each object to be sorted ('name' in [score, name]) as the key for sorting.

    Finally the names from list c are printed to satisfy the problem.