We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
if__name__=='__main__':# Store the names and scores in a liststudents=[]for_inrange(int(input())):name=input()score=float(input())students.append([name,score])# Sort the list of students based on scoresstudents.sort(key=lambdax:x[1])#assign the the second lowest value to a variablesecond_lowest_score=Noneforstudentinstudents:ifsecond_lowest_scoreisNone:second_lowest_score=student[1]elifstudent[1]>second_lowest_score:second_lowest_score=student[1]break# Create a list for names of students with the second lowest scoresecond_lowest_names=[]# Find the names corresponding to the second lowest score and add them to the listforstudentinstudents:ifstudent[1]==second_lowest_score:second_lowest_names.append(student[0])# Sort the list of names alphabeticallysecond_lowest_names.sort()# Print the names from the list of names with the second lowest scorefornameinsecond_lowest_names:print(name)
Cookie support is required to access HackerRank
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 →