One Simple Approach
mainDict = {}
mainDict['id1']={}
mainDict['id1']['id2'] ={}
mainDict['id1']['id2']['id3'] = 'actualVal'
print(mainDict)
# short explanation of defaultdict
import collections
# when a add some key to the mainDict, mainDict will assgin
# an empty dictionary as the value
mainDict = collections.defaultdict(dict)
# adding only key, The value will be auto assign.
mainDict['key1']
print(mainDict)
# defaultdict(<class 'dict'>, {'key1': {}})
# here adding the key 'key2' but we are assining value of 2
mainDict['key2'] = 2
print(mainDict)
#defaultdict(<class 'dict'>, {'key1': {}, 'key2': 2})
# here we are adding a key 'key3' into the mainDict
# mainDict will assign an empty dict as the value.
# we are adding the key 'inner_key' into that empty dictionary
# and the value as 10
mainDict['key3']['inner_key'] = 10
print(mainDict)
#defaultdict(<class 'dict'>, {'key1': {}, 'key2': 2, 'key3': {'inner_key': 10}})