def addSubEntry(mainDict, outerKey, innerKey, innerValue):
    result = dict(mainDict)
inner = dict(result.get(outerKey, {}))
inner[innerKey] = innerValue
result[outerKey] = inner
return result
Python: deep appending to dictionary? - in a single expression