How do you create nested dict in Python?

A nested dict is a dictionary within a dictionary. A very simple thing. >>> d = {} >>> d[‘dict1’] = {} >>> d[‘dict1’][‘innerkey’] = ‘value’ >>> d[‘dict1’][‘innerkey2’] = ‘value2’ >>> d {‘dict1’: {‘innerkey’: ‘value’, ‘innerkey2’: ‘value2’}} You can also use a defaultdict from the collections package to facilitate creating nested dictionaries. >>> import collections >>> … Read more