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.
grades=[]answer=[]#add a line in the given loop to add #names and scores to a NESTED LISTfor_inrange(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=lambdal:(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]foriinrange(len(grades)))#convert the above set into a list#so we can iterate through ituniquelist=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 listforjinrange(len(grades)):ifgrades[j][1]==uniquelist[1]:answer.append(grades[j][0])#print the names you got from the#above step, each one on a new lineforxinanswer:print(x)
Nested Lists
You are viewing a single comment's thread. Return to all comments →
With comments for clarity