Making sure length of matrix row is all the same (python3)

后端 未结 2 1139
执念已碎
执念已碎 2021-01-26 12:44

so I have this python 3 code to input a matrix:

matrix = []
lop=True
while lop:
    line = input()
    if not line:
        lop=False
    if matrix != []:
               


        
2条回答
  •  自闭症患者
    2021-01-26 13:28

    If you want match the first row length, Try this way,

    Use len(matrix[0])

    for row in matrix:
        if len(row) == len(matrix[0]):
            pass
        else:
           print('not same lenght')
    

提交回复
热议问题