首先,对不起,我的英语不是很好! 我有个问题,找不到解决办法。你知道吗
我有这样一个图表:
我有一个函数,它返回如下图形:
data = {
'Finition': {
'Metal': {
'colorCorrect1': {
'Color': {
'aiLayerShader2': {
'colorConstant1': {},
'colorConstant3': {},
'colorConstant2': {
'aiFloatToRgba1': {
'place2dTexture1': {}
}
},
'colorConstant4': {},
'colorConstant5': {
'aiFloatToRgba1': {
'place2dTexture1': {}
}
},
'colorConstant6': {}
}
}
}
}
}
}
我有一个主要组的列表(图片中的蓝色节点): `你知道吗
selection = ['Finition', 'Metal', 'Color', 'colorConstant2']
我需要一个函数,它可以返回特定组的节点列表(在下一个组之前):
返回值应如下所示:
[
['Finition'],
['Metal', 'colorCorrect1'],
['Color', 'aiLayerShader2', 'colorConstant1', 'colorConstant3', 'colorConstant4', 'colorConstant5', 'colorConstant6', 'aiFloatToRgba1', 'place2dTexture1'],
['colorConstant2', 'aiFloatToRgba1', 'place2dTexture1']
]
我尝试了以下方法:
def search_recurssive(element=None, main={}, depth=0):
for key, value in main.items():
if key != element:
if isinstance(value, dict):
search_recurssive(element=element, main=value, depth=depth+1)
else:
pprint(value)
print depth
search_recurssive(element='Metal', main=data)
但没有起作用。非常感谢你的帮助!你知道吗
我刚刚修改了你的代码,使之能像你期望的那样工作
现在,您需要调整它以获得下一个子图并搜索下一个组。你知道吗
编辑: 只是修改了我之前的答案来做选择的全面搜索。你知道吗
这里有一种效率很低的方法:
相关问题 更多 >
编程相关推荐