How can I get a list shape without using numpy?

>>>a = [1,2,3,4,5,6]
>>>print (len(a))
6

For one dimensional lists, the above method can be used. len(list_name) returns number of elements in the list.

>>>a = [[1,2,3],[4,5,6]]
>>>nrow = len(a)
>>>ncol = len(a[0])
>>>nrow
2
>>>ncol
3

The above gives the dimension of the list. len(a) returns number of rows. len(a[0]) returns number of rows in a[0] which is the number of columns.

Here’s a link to original answer.

Leave a Comment