Python - Algorithm to determine if a list is symmetric

前端 未结 6 1697
灰色年华
灰色年华 2021-01-22 00:01

So I\'m stuck on this problem where I\'ve been asked to write an function in Python that checks to see if an n-dimensional array (is that what they\'re called?) is \"symmetric\"

6条回答
  •  轮回少年
    2021-01-22 00:32

    Here's an alternative version for the main test:

    for i, line in enumerate(matrix):
        for j in range(len(line)):
            if a[i][j] != a[j][i]:
                 return False
    return True
    

    Of course that all the other answers that advise you to test if the matrix is square hold true.

提交回复
热议问题