我有2个列表。
list1 = [['vlan 158', ' name MARKE', ' mode vpc'], []]
list2 = [['vlan 158', ' name MARKETING', ' mode vpc'], ['vlan 159', ' name SALES', ' mode vpc']]
list的第一个元素必须匹配,如果匹配则很好,如果不匹配则期望diff作为输出。
预期输出:
+++++++++++++++++ The missing configuration is++++++++++++++
vlan 159
name SALES
mode vpc
+++++++++++++++++ The missing configuration is++++++++++++++
我正在尝试以下操作,但不起作用:
print ("+++++++++++++++++ The missing configuration is++++++++++++++\n")
p = [item for index, item in enumerate(list2) if [] != [it for it in item if it not in list1[index]]]
print('\n'.join(['\n'.join(item) for item in p]))
print ("+++++++++++++++++ The missing configuration is++++++++++++++\n")
q = [item for index, item in enumerate(list1) if [] != [it for it in item if it not in list2[index]]]
print('\n'.join(['\n'.join(item) for item in q]))
请建议如何完成?
当前输出:
+++++++++++++++++ The missing configuration is++++++++++++++
vlan 158
name MARKETING
mode vpc
vlan 159
name SALES
mode vpc
+++++++++++++++++ The missing configuration is++++++++++++++
vlan 158
name MARKE
mode vpc