How to get list rows and columns in Python

2 Answers

0 votes
lst = [[1,2,3], 
       [4,5,6]]

rows = len(lst)
cols = len(lst[0])

print("Rows: " + str(rows))
print("Columns: " + str(cols))


      
  
'''
run:
  
Rows: 2
Columns: 3

'''

 



answered Apr 17, 2021 by avibootz
0 votes
import numpy as np

lst = [[1,2,3], 
       [4,5,6]]

result = (np.shape(lst))

print(result)

print("Rows: " + str(result[0]))
print("Columns: " + str(result[1]))


      
  
'''
run:
  
(2, 3)
Rows: 2
Columns: 3

'''

 



answered Apr 17, 2021 by avibootz
...