Let's say I have a dictionary like this
{
"level1": {
"stuff": 1,
"morestuff": 2,
"otherstuff": {
"this": 9.2
}
}
}
And I have a list of keys like this ['level1'] or ['level1', 'stuff'].
Right now, my solution is find the length of the list and pass the keys given their number
if len(dictionary) == 1 :
return dictionary['level1']
elif len(dictionary) == 2 :
return dictionary['level1']['morestuff']
...
Is there a way to pass the keys dynamically to explore the dictionary?