# This program displays a list of strings in a table
#
# Write a function named printTable() that takes a list of lists of strings and
# displays it in a well-organized table with each column right-justified. Assume
# that all the inner lists will contain the same number of strings.
#
# For example, the value could look like this:
# tableData = [['apples', 'oranges', 'cherries', 'banana'],
#              ['Alice', 'Bob', 'Carol', 'David'],
#              ['dogs', 'cats', 'moose', 'goose']]
#
# Your printTable() function would print the following:
#   apples Alice  dogs
#  oranges   Bob  cats
# cherries Carol moose
#   banana David goose


def printTable(matrix):
    # Calculate length of longest word in each row
    colWidths = []
    for row in matrix:
        maxWidth = 0
        for item in row:
            if len(item) > maxWidth:
                maxWidth = len(item)
        colWidths.append(maxWidth)

    # Sort lengths of words in each row and find longest word in matrix
    colWidths = sorted(colWidths)
    maxWidth = colWidths[-1]

    # Print each column with right-justification of longest word in matrix
    for index in range(len(matrix[0])):
        output = ""
        for row in matrix:
            output += row[index].rjust(maxWidth)
        print(output)


def main():
    tableData = [['apples', 'oranges', 'cherries', 'banana'],
                 ['Alice', 'Bob', 'Carol', 'David'],
                 ['dogs', 'cats', 'moose', 'goose']]
    printTable(tableData)


if __name__ == "__main__":
    main()

@@ -645,25 +645,26 @@
 %0A%0A%0Adef print
-T
+_t
 able(matrix)
@@ -715,33 +715,34 @@
 each row%0A    col
-W
+_w
 idths = %5B%5D%0A    f
@@ -766,25 +766,26 @@
 %0A        max
-W
+_w
 idth = 0%0A   
@@ -832,25 +832,26 @@
 (item) %3E max
-W
+_w
 idth:%0A      
@@ -859,25 +859,26 @@
          max
-W
+_w
 idth = len(i
@@ -889,25 +889,26 @@
 %0A        col
-W
+_w
 idths.append
@@ -907,25 +907,26 @@
 s.append(max
-W
+_w
 idth)%0A%0A    #
@@ -995,25 +995,26 @@
 trix%0A    col
-W
+_w
 idths = sort
@@ -1019,17 +1019,18 @@
 rted(col
-W
+_w
 idths)%0A 
@@ -1035,17 +1035,18 @@
 %0A    max
-W
+_w
 idth = c
@@ -1047,17 +1047,18 @@
 th = col
-W
+_w
 idths%5B-1
@@ -1264,17 +1264,18 @@
 just(max
-W
+_w
 idth)%0A  
@@ -1313,25 +1313,26 @@
 ):%0A    table
-D
+_d
 ata = %5B%5B'app
@@ -1482,25 +1482,26 @@
 %5D%5D%0A    print
-T
+_t
 able(tableDa
@@ -1498,17 +1498,18 @@
 le(table
-D
+_d
 ata)%0A%0A%0Ai

Update P01_tablePrinter: fixed PEP8 variables and function