I have the the following input variables: 'PATH', which is an array containing keys to create to and 'output_content' which is a dictionary where the keys should be created in, 'output content' already contains key-value pairs, and they should not be lost.
For example: considering PATH = ['patterns', 'pattern_1', 'children', 'pattern_1_1']
, the resulting 'output_content' dictionary should look like this:
{
'patterns': {
'pattern_1': {
'children': {
'pattern_1_1': {}
}
}
},
'already_existing_key': 'already_existing_value'
}
I've tried the following:
current_dict = output_content
for key in PATH[1:]:
if key not in current_dict:
current_dict[key] = {}
current_dict = current_dict[key]
But soon i realized that the it just wouldn't work because output_content is changing according to current_dict, so the resulting output will be just {}
.