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.
I use dict to store score: [names] pairs, get the appropriate names list using the second key in the sorted keys, then print the unpacked sorted result using sep='\n'.
This takes care of the duplicate grades because the grades are the key.
d={}#dictfor_inrange(int(input())):name=input()score=float(input())# if the score has names associated, get the list, otherwise empty listscore_names=d.get(score,[])# append to list and store list back in dict (just in case it's new)score_names.append(name)d[score]=score_names# get the second of the keys when sorted ascending, use it for the dict to get names, sort + unpack to printprint(*sorted(d[sorted(d.keys())[1]]),sep='\n')
Nested Lists
You are viewing a single comment's thread. Return to all comments →
I use dict to store score: [names] pairs, get the appropriate names list using the second key in the sorted keys, then print the unpacked sorted result using sep='\n'.
This takes care of the duplicate grades because the grades are the key.