Skip to content
loading...

re: Why you should never use the dict.get() method in Python VIEW POST

FULL DISCUSSION
 

I completely disagree. Panel Morava makes good points, but one I don't think he emphasizes enough is that the ambiguity is only a problem if None is a value that might be in the dictionary. If I have a dictionary scores with string player names as keys and their values as lists of ints, I know that a key's value will never be None. Honestly, there are few cases where having multiple types of values in the same dict is not a bad idea. dict.get is helpful whenever the desired behavior on a missing key is just to proceed with a default.

code of conduct - report abuse