• + 1 comment

    With comments for clarity

    grades = []
    answer = []
    #add a line in the given loop to add 
    #names and scores to a NESTED LIST
    for _ in range(int(input())):
        name = input()
        score = float(input())
        grades.append([name, score])
    
    #sort the nested list by scores,
    #then by name (in case of a tie)
    grades.sort(key = lambda l: (l[1], l[0]))
    
    #make a SET of just the scores to
    #remove repeat values (so we will
    #know which score is 2nd lowest)
    gradeset = set(grades[i][1] for i in range(len(grades)))
    
    #convert the above set into a list
    #so we can iterate through it
    uniquelist = list(gradeset)
    
    #iterate through the nested list
    #if the grade in the list is equal
    #to the second score in the unique
    #list, add that person's name to
    #the final answer list
    for j in range(len(grades)):
        if grades[j][1] == uniquelist[1]:
            answer.append(grades[j][0])
    
    #print the names you got from the
    #above step, each one on a new line
    for x in answer:
        print(x)