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.
According to the problem description, it's the names of the students who got the second lowest score we're looking for. My code certainly finds the lowest two scores and since my code passes the tests, that seems to be what's wanted. Can't remember precisely what I was thinking when I called the variable top2 - the two most significant and/or the two which would be at the top if you sorted the list in descending order, I suppose.
You're wrong about what logScore does. Its responsibility is to add the score to the list of the two lowest scores if it is one of the two lowest scores we've seen so far. It returns True if the score is currently one of the two lowest, False otherwise.
The program checks the result; if the returned value is True, then score is currently one of the two lowest scores (lowest or second lowest) and we should keep a record of the name associated with it. But recording the name isn't logScore's responsibility.
To be honest, logScore probably has either too much responsibility or not enough; either a separate function should manage both the addition of names to the dictionary and their removal if a score drops out of the lowest-two-scores list, or logScore should completely manage both the top2 list and the scores dictionary. As it is, it's a little messy. My excuse was that it was a quick change made to my code at somebody else's request.
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 →
According to the problem description, it's the names of the students who got the second lowest score we're looking for. My code certainly finds the lowest two scores and since my code passes the tests, that seems to be what's wanted. Can't remember precisely what I was thinking when I called the variable top2 - the two most significant and/or the two which would be at the top if you sorted the list in descending order, I suppose.
You're wrong about what logScore does. Its responsibility is to add the score to the list of the two lowest scores if it is one of the two lowest scores we've seen so far. It returns True if the score is currently one of the two lowest, False otherwise.
The program checks the result; if the returned value is True, then score is currently one of the two lowest scores (lowest or second lowest) and we should keep a record of the name associated with it. But recording the name isn't logScore's responsibility.
To be honest, logScore probably has either too much responsibility or not enough; either a separate function should manage both the addition of names to the dictionary and their removal if a score drops out of the lowest-two-scores list, or logScore should completely manage both the top2 list and the scores dictionary. As it is, it's a little messy. My excuse was that it was a quick change made to my code at somebody else's request.