想知道我在这里做错了什么,我正在尝试比较层次结构,以便在从两个单独的层次结构(first_sel_list 和 second_sel_list)形成我的列表时,我可以将具有相同名称的项目与 PSR 标签链接在一起,我在减少的列表中得到额外的结果.
first_sel_list = ['First_Null', 'Cube', 'Cube.1', 'Cube.2', 'Cube.3', 'Cube.4', 'Cube.5', 'Cube.6', 'Ignore_Top_0', 'Ignore_Top_1', 'Ignore_Top_2', 'Ignore_Top_Child_00', 'Ignore_Top_Child_01', 'Ignore_Top_Child_02', 'Ignore_Top_Child_03', 'Cube.7']
second_sel_list = ['Second_Null', 'Cube', 'Cube.1', 'Cube.2', 'Cube.3', 'Shit_Bot_0', 'Ignore_Bot_1', 'Ignore_Bot_2', 'Cube.4', 'Cube.6', 'Cube.7', 'Cube.5']
link_list = ['Cube', 'Cube.1', 'Cube.2', 'Cube.3', 'Cube.4', 'Cube.5', 'Cube.6', 'Cube.7']
for name in first_sel_list:
if name not in link_list:
first_sel_list.remove(name)
for name in second_sel_list:
if name not in link_list:
second_sel_list.remove(name)
print ('LINK LIST ' + str(link_list))
print ('Edited First list ' + str(first_sel_list))
print ('Edited Second list ' + str(second_sel_list))
输出:
LINK LIST ['Cube', 'Cube.1', 'Cube.2', 'Cube.3', 'Cube.4', 'Cube.5', 'Cube.6', 'Cube.7']
Edited First list ['Cube', 'Cube.1', 'Cube.2', 'Cube.3', 'Cube.4', 'Cube.5', 'Cube.6', 'Ignore_Top_1', 'Ignore_Top_Child_00', 'Ignore_Top_Child_02', 'Cube.7']
Edited Second list ['Cube', 'Cube.1', 'Cube.2', 'Cube.3', 'Ignore_Bot_1', 'Cube.4', 'Cube.6', 'Cube.7', 'Cube.5']
预期输出:
LINK LIST ['Cube', 'Cube.1', 'Cube.2', 'Cube.3', 'Cube.4', 'Cube.5', 'Cube.6', 'Cube.7']
Edited First list ['Cube', 'Cube.1', 'Cube.2', 'Cube.3', 'Cube.4', 'Cube.5', 'Cube.6', 'Cube.7']
Edited Second list ['Cube', 'Cube.1', 'Cube.2', 'Cube.3', 'Cube.4', 'Cube.6', 'Cube.7', 'Cube.5']
层次结构的图片: