Python - Default Dict - Simplify handling of missing keys in dictionaries
defaultdict(default_factory, **kwargs)is a subclass of Python standard dictionary (dict).
Python creators added several "versions" of standard dict implementation to answer some of the most common
user problems.
If you call a non existent key in a standard, normal dict in Python you will get a KeyError.
You can avoid this with get() method but if you would like to provide a default value for all keys that you will
call in your dict, then defaultdict is a way to go.
To use defaultdict, you must import it from the collections module.
default_factory needs to be a callable (such as int, list, lambda, etc.) used to calculate the default value.
It cannot accept arguments and must return the value to be used as the default.
Note: If defaultdict is initialized without a default_factory, it behaves like a regular dictionary and will raise a KeyError for missing keys.