SyntaxFix
Write A Post
Hire A Developer
Questions
You need the key in dict idiom for that.
key in dict
if key in my_dict and not (my_dict[key] is None): # do something else: # do something else
However, you should probably consider using defaultdict (as dF suggested).
defaultdict