比较二维列表和 return 索引的不同之处

Compare 2D lists and return index where they differ

我想比较两个相似列表的元素和 return 它们不同的索引。

列表仅在一处不同。

def coord(a,b):
    for i in range(0,3):
        for j in range(0,3):
            if a[i][j] != b[i][j]:
                return # index where they differ


a = [[0,0,2],[2,1,1],[0,1,0]]
b = [[2,0,2],[2,1,1],[0,1,0]]

print(coord(a,b))

首选输出:[0,0]

将 return 列表不同的每个索引

temp= []
def coord(a,b):
    for i in range(0,3):
        for j in range(0,3):
            if a[i][j] != b[i][j]:
                temp.append([i,j])
    print temp

a = [[0,0,2],[2,1,1],[0,1,0]]
b = [[2,0,2],[2,1,1],[0,1,0]]

coord(a,b)