yunyuyuyu123 2019-10-01 13:03 采纳率: 0%
浏览 317

Python关于递归的问题

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

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2019-10-01 23:10
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 SQL Server下载
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求