Skip to content

Instantly share code, notes, and snippets.

@cherylli
Last active August 30, 2019 12:12
Show Gist options
  • Save cherylli/c1962c425b0a58c5d684fef8b595793f to your computer and use it in GitHub Desktop.
Save cherylli/c1962c425b0a58c5d684fef8b595793f to your computer and use it in GitHub Desktop.
Automate the Boring Stuff with Python, Chaper 6 Practice Project, PrintTable
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