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 used your code within my own understanding of the challenge, I tried to explain this to help myself understand, hopefully this can help others can understand too (and if anyone can let me know if i need to improve any of it!)
I break down the descriptions of what each statement does ABOVE each statement.
studentList=[]foriinrange(int(input())):name=input()score=float(input())studentList.append([name,score])# for each nest in studentList# sort via the score in ascending# with {} within sorted[] it creates a "set"# output is [37.2, 37.21, 39, 41] - sets remove additonal same numbersscoreSort=sorted({s[1]forsinstudentList})# for each nest in studentList (s)# return a sorted list (sorted by their names (s[0])) of students whos score (s[1]) is equal to s[1] in scoreSort# nameSort = ["Berry", "Harry"]nameSort=sorted(s[0]forsinstudentListifs[1]==scoreSort[1])#.join(nameSort) takes each element in the nameSort list# so ["Berry", "Harry"]# "\n" seperates using a newline BETWEEN each element# output is "Berry\nHarry"print('\n'.join(nameSort))
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 →
I used your code within my own understanding of the challenge, I tried to explain this to help myself understand, hopefully this can help others can understand too (and if anyone can let me know if i need to improve any of it!)
I break down the descriptions of what each statement does ABOVE each statement.