我有两个清单。我想将每个列表的“a”的列表索引 [1][2][3] 与“b”的其他列表索引 [1][2][3] 相互比较。如果匹配,则ignore ,如果没有则返回整个列表。
a = [['Eth1/1/13', 'Marketing', 'connected', '10', 'full', 'a-1000'], ['Eth1/1/14', 'NETFLOW02', 'connected', '10', 'full', '100']]
b = [['Eth1/1/13', 'NETFLOW02', 'connected', '15', 'full', '100'], ['Eth1/1/14', 'Marketing', 'connected', '10', 'full', 'a-1000']]
期望输出:
Diff a:
Eth1/1/14 NETFLOW02 connected 10 full 100
Diff b:
Eth1/1/13 NETFLOW02 connected 15 full 100
我正在尝试什么:
p = [i for i in a if i not in b]
for item in p:
print item[0]
print "\n++++++++++++++++++++++++++++++\n"
q = [i for i in b if i not in a]
for item in q:
print item[0]
下面尝试过,但只设法匹配内部列表的索引 1,索引 2 和 3 仍然需要匹配..
[o for o in a if o[1] not in [n[1] for n in b]
我没有得到预期的输出。知道怎么做吗?
炎炎设计
慕娘9325324
相关分类