From the following nested dictionary, how can I get every parent dictionary key of 'value4ac'
? By starting the 'value4ac'
value, I want to get 'key4'
, 'key4a'
, 'Key4ac'
.
example_dict = { 'key1' : 'value1',
'key2' : 'value2',
'key3' : { 'key3a': 'value3a' },
'key4' : { 'key4a': {
'key4aa': 'value4aa',
'key4ab': 'value4ab',
'key4ac': 'value4ac'
},
'key4b': 'value4b'
}
}
recursion to the rescue!
how it works
It looks through the items and checks 2 cases