I have the following nested dict:
ex_dict = {'path1':
{'$variable1': '2018-01-01',
'$variable2': '2020-01-01',
'$variable3': '$variable1',
'$variable4': '$variable3'},
'path2':
{'$variable1': '2018-01-01',
'$variable2': '2020-01-01',
'$variable3': '$variable1',
'$variable4': '$variable1 + $variable2'}
}
I want to replace any $variableX specified for a dict key with the dict value from another key if the key from the other dict value if found in the value of the original dict key. See example output below:
{'path1':
{'$variable1': '2018-01-01',
'$variable2': '2020-01-01',
'$variable3': '2018-01-01', # Substituted with value from key:variable1
'$variable4': '2018-01-01'}, # Substituted with value from key:variable3 (after variable3 was substituted with variable1)
'path2':
{'$variable1': '2018-01-01',
'$variable2': '2020-01-01',
'$variable3': '2018-01-01', # Substituted with value from key:variable1
'$variable4': '2018-01-01 + 2020-01-01'} # Substituted with value from key:variable3 (after variable3 was substituted with variable1) and key:variable2
}
Does anyone have any suggestions?