2024-10-01 22:34:36 发布
网友
当试图通过忽略层次结构来获取嵌套字典中键的值时,它总是返回None
None
def nested(d,key): for i in d.keys(): if i == key: return d[i] elif isinstance(d[i], dict): nested(d[i],key) j = {'hello': {'foo': {'bar': {'world':'yeay'}}}} print(nested(j,'world'))
当然,预期的答案是yeay,但我遗漏了什么
yeay
目前没有回答
目前没有回答
相关问题 更多 >
编程相关推荐