Assuming that we have a nested dictionary (or json) and we want to access certain keys/subkeys at various levels, is there a way to send the desired key path to return only the expected data?
If we have a dictionary like the one below:
dct = {'A': {'A1': {'A11': 'something', 'A12': 'something else'}},
'B': {'B1': 'old thing', 'B2': 'new thing'},
'C': 'no level'}
is there an elegant python way of specifying the keys we want to select?
Obviously this works, but is not very elegant...
print(dct['A']['A1']['A12'])
print(dct['B']['B2'])
print(dct['C'])
Ideally, we could have a list of the subset keys we want to return.