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.
My idea is that first, I create 2 lists called student and test. The student list contains name and score, while the test list only contains score. Then the test list's duplicated scores will be removed and this list will be sorted in ascending order. Next, I set the second_lowest_score (i) to be the second value of that list (or test[1]). After that, I loop through the student list and find the name that have the satisfied score and order those name alphabetically.
if__name__=='__main__':# store student's information in a liststudent=[]test=[]for_inrange(int(input())):name=input()score=float(input())student.append([name,score])test.append(score)# Remove duplicates and sort scores in increasing ordertest=sorted(list(set(test)))# i = second lowest grade; store all the satisfied names in list_namei=test[1]list_name=[]forainstudent:ifa[1]==i:list_name.append(a[0])# Order their names alphabeticallylist_name.sort()fornameinlist_name: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 →
My idea is that first, I create 2 lists called student and test. The student list contains name and score, while the test list only contains score. Then the test list's duplicated scores will be removed and this list will be sorted in ascending order. Next, I set the second_lowest_score (i) to be the second value of that list (or test[1]). After that, I loop through the student list and find the name that have the satisfied score and order those name alphabetically.