#回溯算法 获取字典所有值的键的集合
def get_dict_path(data):
ret = []
path =[]
def traceback(path,data):
if len(path)>0 and not isinstance(data, dict):
ret.append(path[:])
return
for k, v in data.items():
path.append(k)
traceback(path, v)
path.pop()
traceback(path,data)
return ret
#递归获取全部的值
def get_dict_value(data):
for k, v in data.items():
if isinstance(v, dict):
get_dict_value(v)
else:
ret.append(v)
get_dict_value(demo_dect)
标签:get,python,路径,ret,dict,path,data,字典 From: https://www.cnblogs.com/fujianguo1024/p/17255166.html