blob: 83b20c15a595604a209cb0333dc7cb13ca02fa32 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#! /usr/bin/env python3
# Table Printer Chap. 6
# Function for taking lists of strings and displays in an organized table
tableData = [['apples','oranges','cherries','bananas'],
['Alice','Bob','Carol','David'],
['dogs','cats','moose','goose']]
def printTable(dataLists):
colWidths = [0] * len(dataLists)
for i in colWidths:
colWidths = max(dataLists[i], key=len)
y = len(colWidths)
for x in range(len(dataLists[0])):
print(str(dataLists[0][x]).rjust(y) + str(dataLists[1][x]).rjust(y) + str(dataLists[2][x]).rjust(y))
printTable(tableData)
|