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.
So if logScore(score) returned true, score is one of the two lowest scores we've seen so far, which means we want to add the name to the list of names associated with that score (if it isn't one of the lowest two, we don't care). Which is what the line above does.
So we want to fetch the list of names associated with score in the scores dictionary. But what if this is the first time we've seen this score? In that case, there will be no entry - trying to fetch it will raise an error. However, if we provide a default value, get() will return that default value if score is not a key in the scores dictionary.
So that line fetches the existing list from the dictionary or returns an empty list if there is no entry for score in the dictionary. Then we add name to the end of that list and put the resulting list into the dictionary as the list associated with score.
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 →
OK, third and final line:
So if logScore(score) returned true, score is one of the two lowest scores we've seen so far, which means we want to add the name to the list of names associated with that score (if it isn't one of the lowest two, we don't care). Which is what the line above does.
So we want to fetch the list of names associated with score in the scores dictionary. But what if this is the first time we've seen this score? In that case, there will be no entry - trying to fetch it will raise an error. However, if we provide a default value, get() will return that default value if score is not a key in the scores dictionary.
So that line fetches the existing list from the dictionary or returns an empty list if there is no entry for score in the dictionary. Then we add name to the end of that list and put the resulting list into the dictionary as the list associated with score.