""" Purpose: introductory take on examining a table of values """ # define table table = [ ["A", "B", "C" ], [ "D", "E", "F" ], [ "G", "H", "I" ], [ "J", "K", "L", "M" ] ] print( "table:", table ) print() # determine number of rows in table nrows = len( table ) # len( table ) returns the number of lists in our larger list table, which is the number of rows print( "the table has", nrows, "rows" ) print() # print each row of the table along withs number of columns for row in table : # row is our loop variable that will take on a different list each run of the for loop # everywhere that we type row means that is a place that we want to process each row of the table ncols = len( row ) # len( row ) is the number of elements in that list, which is the number of columns # note: the column number can vary from row to row print( "row", row, "has", ncols, "columns" ) print() # print each row of the table using row indices for r in range( 0, nrows ) : # processing and printing in a for loop can help with readability, as we want rows to be on different # lines of output # sometimes the r/index is going to be handy, so remember anytime you're processing a list you can # loop through the list or use the range() and access the list using indices row = table[ r ] # you find rows through indexing your dataset/table data[ row ] is going to be a list print( "row", r, ":", row )