我有两个这样的列表
Nodelist1=[[['B', 10], ['IN', 1000]], [['C', 15], ['OUT', 1001]], [['F', 30], ['IN', 1100]]]
Nodelist2= [[['G', 20], ['IN', 1000, 'OUT', 1111]], [['D', 25], ['INWARD', 1]]]
我想做的是像这样比较这两个列表
if len(Nodelist1[i][1])==len(Nodelist2[j][1])
如果条件为真,那么我想删除Nodelist1[i][0]
which is ['B', 10]
and fromNodelist1
和Nodelist2[j][1]
which is ['D', 25]
from Nodelist2
。
那我应该有
Nodelist1 as [[['C', 15], ['OUT', 1001]], [['F', 30], ['IN', 1100]]]
Nodelist2 as [[['G', 20], ['IN', 1000, 'OUT', 1111]]]
我的代码是这样的:
if len(Nodelist1)>len(Nodelist2):
for i in range(len(Nodelist1)):
for j in range(len(Nodelist2)):
if len(Nodelist1[i][1])==len(Nodelist2[j][1]):
if Nodelist1[i][1]==Nodelist2[j][1]:
Nodelist1.remove(Nodelist1[i])
Nodelist2.remove(Nodelist2[j])
else:
Nodelist1.remove(Nodelist1[i])
Nodelist2.remove(Nodelist2[j])
它给了我一个错误:
if len(Nodelist1[i][1])==len(Nodelist2[j][1]):
IndexError: list index out of range