Python - Algorithm to determine if a list is symmetric

前端 未结 6 1660
灰色年华
灰色年华 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:30

    You can put this check at the start of your function:

    for row in square:
        if len(row) != len(square):
            return False
    

    Or maybe shorter

    if not all(len(square) == len(row) for row in square): return False
    

提交回复
热议问题