Another solution:
d = { 'A' : { 'C' : { 'D' : { 'E' : 4, }, 'F' : 5, }, }, 'B' : 2, } def DeepDictDel(path, dict): for key in path.split('.'): owner = dict dict = dict[key] del owner[key] print d # prints {'A': {'C': {'D': {'E': 4}, 'F': 5}}, 'B': 2} DeepDictDel('ACD', d) print d # prints {'A': {'C': {'F': 5}}, 'B': 2}
source share