在这里插入代码片
def get_dict_value(date, keys, default=None):
keys_list = keys.split('.')
if isinstance(date, dict):
dictionary = dict(date)
for i in keys_list:
try:
if dictionary.get(i) != None:
dict_values = dictionary.get(i)
elif dictionary.get(i) == None:
dict_values = dictionary.get(int(i))
except:
return default
dictionary = dict_values
return dictionary
else:
try:
dictionary = dict(eval(date))
if isinstance(dictionary, dict):
for i in keys_list:
try:
if dictionary.get(i) != None:
dict_values = dictionary.get(i)
elif dictionary.get(i) == None:
dict_values = dictionary.get(int(i))
except:
return default
dictionary = dict_values
return dictionary
except:
return default
获取多层嵌套字典
最新推荐文章于 2022-02-06 13:44:21 发布