0

我想检查像下面这样的乘法表是否不是代码,但我找不到另一种写法

*  0 1 2
0 |0 1 0
1 |0 0 0 
2 |0 1 1

它在我的代码中存储为带有子列表的列表,例如

[[0,1,0], [0,0,0], [0,1,1]]

#How to write a function which checks elements satisfy the condition x*(y*z) = (x*y)*z ? 

#This is what I have so far: 

def is_associative(X):
    n = len(X)
    a = []
    for i in range(n):
        a.append[i]
        for j in range(n):
            a[j]*a[j] = X[j]
4

1 回答 1

1

您应该遍历所有三个变量:

for x in range(n):
    for y in range(n):
        for z in range(n):

然后你需要检查是否

X[X[x, y], z] == X[x, X[y, z]]

对于所有值。

于 2019-04-17T01:18:17.767 回答