問題:
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