问题:
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