check if key exists pythondict code example
Example 1: defaultdict check if key exists
dct.get(key, 'ham') # will return dct[key] or 'ham' but never stores anything
Example 2: how to know if a key is in a dictionary python
dict = {"key1": 1, "key2": 2}
if "key1" in dict: