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.
Two simple ways to improve this without abandoning the basic idea.
Create the set of marks at the same time as creating the marksheet. Just put "marks = set()" at the beginning, then in the for loop add the score to that set as well as to the marksheet. Then there's no need to traverse marksheet to extract the marks and put them in a set - they're already there. ** "second_highest = sorted(scores)[1]"**
Filter marksheet to extract only the names of students who have the right score and then sort them. This answer does it the wrong way round; why bother sorting names you're going to throw away?
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 →
Two simple ways to improve this without abandoning the basic idea.