Last active
August 30, 2019 12:12
-
-
Save cherylli/c1962c425b0a58c5d684fef8b595793f to your computer and use it in GitHub Desktop.
Automate the Boring Stuff with Python, Chaper 6 Practice Project, PrintTable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def printTable(table): | |
col_widths = getLongestWordLength(table) | |
for i in range(len(table[0])): | |
for j in range(len(table)): | |
print(table[j][i].rjust(col_widths[j]), end=' ') | |
print() | |
def getLongestWordLength(table): | |
return[max([len(item) for item in line]) for line in table] | |
tableData = [['apples', 'oranges', 'cherries', 'banana'], | |
['Alice', 'Bob', 'Carol', 'David'], | |
['dogs', 'cats', 'moose', 'goose']] | |
printTable(tableData) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment