This type of dictionary will be useful by default for two levels of data. Something like that:
{ k11 : { k21 : [...], k22 : [...] }, k12 : { ... } }
Every dictionary is here defaultdict.
lambdareturns defaultdictfor the second level when the key of the first level does not exist:
In [234]: final['k11'] # first level access
Out[234]: defaultdict(list, {})
In [235]: final['k11']['k21'] # second level access
Out[235]: []
source
share