Alan Wakke Alan Wakke - 6 months ago 49
Python Question

Count rows and columns

How would I go about defining a fuctions in counting the number of rows and columns in a list of lists? For example group1 would be 1 row with 6 columns.

group1 = [['.', 'A', 'A', '.', '.', '.']]

def num_rows(group):

def num_columns(group):


Just check the first index:

def num_rows(group):
    return len(group)

def num_columns(group):
    return len(group[0])

Take in mind this will raise an IndexError exception if there's no rows.