获取嵌套字典值的安全方法 - Safe method to get value of nested dictionary

问题:

I have a nested dictionary.我有一个嵌套字典。 Is there only one way to get values out safely?只有一种方法可以安全地获取值吗?

try:
    example_dict['key1']['key2']
except KeyError:
    pass

Or maybe python has a method like get() for nested dictionary ?或者 python 有一个像get()的嵌套字典的方法?


解决方案:

参考一: https://en.stackoom.com/question/1kOVB
参考二: https://stackoom.com/question/1kOVB
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章