''' 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 ) print( "the table has", nrows, "rows" ) print() # print each row of the table along withs number of columns for row in table : ncols = len( row ) print( "row", row, "has", ncols, "columns" ) print() # print each row of the table using row indices for r in range( 0, nrows ) : row = table[ r ] print( "row", r, ":", row ) print() # individually print in people form the cells in the list of rows for row in table : print( "row :", end=" " ) for cell in row : print( cell, end=" " ) print() print() # individually print each row and column of the table using row # and column indices to look into the table for r in range( 0, nrows ) : row = table[ r ] ncols = len( row ) print( "row", r, ":", row ) for c in range( 0, ncols ) : cell = table[ r ][ c ] print( " column", c, "of row", r, ":", cell ) print() # print the table in people form using row and column indices # to look into the table for r in range( 0, nrows ) : print( "row", r, ":", end=" " ) ncols = len( table[ r ] ) for c in range( 0, ncols ) : cell = table[ r ][ c ] print( cell, end=" " ) print() print() # print a requested column as a list reply = input( "Enter column of interest: " ) c = int( reply ) # need to accumulate the cells in the column c column = [] for row in table : # get cell in column c of the row cell = row[ c ] column.append( cell ) print( "Column", c, "cell:", cell ) print() print( "Column", c, ":", column )