automate-boring-stuff/exercises/ex06/ex06a.py

21 lines
520 B
Python

tableData = [
["apples", "oranges", "cherries", "banana"],
["Alice", "Bob", "Carol", "David"],
["dogs", "cats", "moose", "goose"],
]
def printTable(table):
msg = ""
for i, row in enumerate(table):
width = list(sorted(map(lambda x: len(x), row)))[-1] + 1
table[i] = list(map(lambda y: y.rjust(width), row))
for i in range(0, len(table[0])):
for j in range(0, len(table)):
msg += table[j][i]
msg += "\n"
print(msg.rstrip())
printTable(tableData)