我创建了一个加权边缘列表,其中包含:
for key1, value1 in x1.items():
for key2, value2 in x2.items():
weight = 1 / (value1 + value2)
row.append((key1, key2, str(weight)))
之后,列表列表包含重复项。例如:
[(a,a,0.5), ..., (a,b,0.2),..., (b,a,0.2), ..., (z,z,0.5)]
我的方法不起作用:
i = 0
j = 0
for row1 in matrix:
for row2 in matrix:
if(matrix[i][0] == matrix[j][1]):
del(matrix[j])
j +=1
i +=1
我会得到这个按摩:
if(matrix[i][0] == matrix[j][1]):
IndexError: list index out of range
我究竟做错了什么?