defaultdict in python
defaultdict:
Defaultdict is a container like dictionaries present in the module collections.
The functionality of both dictionaries and defualtdict are almost same except for the fact that defualtdict never raises a KeyError
. It provides a default value for the key that does not exists.
formation:
defaultdict(<class 'list'>, {0: [0], 1: [1], 2: [2], 3: [3], 4: [4]})
defaultdict(<class 'int'>, {1: 2, 2: 3, 3: 1, 4: 2})