I just started learning python with small scripts. I came across a quiz to determine a list to be symmetric if the first row is the same as the first column, the second row is the same as the second column and so on.
def symmetric(block):
n = len(block)
i = 0
for i in range(n-1):
j = 0
for j in range(n-1):
if (block[i][j] != block[j][i]):
return False
j +=1
i +=1
return True
So the result of
print symmetric([["cat", "dog", "fish"],
["dog", "dog", "dog"],
["fish","fish","cat"]])
should be False.
However, this code always return True, and in debugger I can see block[i][j] != block[j][i] returns True but the if block is not executed. Is there anything wrong with the comparison or the if block is not correctly composed?
Aucun commentaire:
Enregistrer un commentaire