You've recieved a serialized JSON object from an API and have deserialized it using the standard library's json library. The object represents your geneology from a given ancestor downward. Assuming your name is Sally and your given ancestor is Janet, your geneology object would be as follows:
geneology_object = {
'husband': 'Craig',
'wife': 'Janet',
'children': {
'Chris': {
'husband': 'Chris',
'wife': 'Jesse',
'children': {
'Rebecca': {
'husband': 'Doug',
'wife': 'Rebecca',
}
}
},
'Wonda': {
'husband': 'Kevin',
'wife': 'Wonda',
'children': {
'Sally': {}
}
}
}
}
Write a function with the signature get_generations_down(geneology_object, search_name, generations=0) to recursively search for the number of generations between search_name and the eldest ancestor. If the name is not found, a NameNotFoundError should be raised by the recursive function.
Assuming the geneology object above, your function should behave as so:
get_generations_down(geneology_object, 'Chris')
1
get_generations_down(geneology_object, 'Sally')
2