獲取嵌套字典值的安全方法 - 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章