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.
Find the third score in the list xs (which will be the highest score of the three, the one we don't want to keep)
Delete that score and its list of names from the scores dictionary and return the value of that list. If there is no such entry in the dictionary, return None.
scores.pop is a method belonging to the dictionary class. It modifies the dictionary it belongs to, it doesn't modify the values passed to it. It always needs one parameter which is the key to fetch/remove from the dictionary. It optionally takes a second value, which is a default value to use if there is no such key in the dictionary.
I don't do anything with the returned value, I ignore it, so it could return anything and it wouldn't matter. I'm only providing a default value to stop pop from complaining if there is no such key in the dictionary. I use the pop method rather than the del function because popcan be made not to complain; I know there will be occasions where there is no such key and I'd rather use a function that doesn't mind, rather than have to make that check myself. I provide None as the default value to make it clearer that I don't care about the result (and to not waste the program's time by having it create and store a value that will never be used).
Nested Lists
You are viewing a single comment's thread. Return to all comments →
No, it means
scores.pop is a method belonging to the dictionary class. It modifies the dictionary it belongs to, it doesn't modify the values passed to it. It always needs one parameter which is the key to fetch/remove from the dictionary. It optionally takes a second value, which is a default value to use if there is no such key in the dictionary.
I don't do anything with the returned value, I ignore it, so it could return anything and it wouldn't matter. I'm only providing a default value to stop pop from complaining if there is no such key in the dictionary. I use the pop method rather than the del function because pop can be made not to complain; I know there will be occasions where there is no such key and I'd rather use a function that doesn't mind, rather than have to make that check myself. I provide None as the default value to make it clearer that I don't care about the result (and to not waste the program's time by having it create and store a value that will never be used).