Search code examples
pythonlistmultidimensional-arrayrowcol

How can I get the number of columns and rows from 2D list


I create a 2D List with n cols and m rows:

2DList = [[0 for x in range(cols)] for y in range(rows)]

How can I get the number of cols and rows with the simple method?


Solution

  • No.of rows = len(matrix)

    No.of cols = len(matrix[0]), if all the rows are of same size