如果我得到了您想要的东西,就不要确定,但是您可能想要这样做:
def traverse(dic, path=None):
if not path:
path = []
for i in dic:
local_path = path[:].append(i)
if i['type'] == 'folder':
for j in traverse(i['children'], local_path):
yield j, local_path
elif i['type'] == 'url':
yield i, local_path
现在,您的函数会产生该项目和一系列键,以便在特定位置到达该项目。