-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtablePrinter.py
More file actions
27 lines (20 loc) · 773 Bytes
/
Copy pathtablePrinter.py
File metadata and controls
27 lines (20 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
tableData = [['apples', 'oranges', 'cherries', 'banana'],
['Alice', 'Bob', 'Carol', 'David'],
['dogs', 'cats', 'moose', 'goose']]
rowCount = len(tableData)
# print(rowCount) 3
columnCount = len(tableData[0])
# print(columnCount) 4
#figuring out the right width for each column
columnWidth = [0] * len(tableData)
# print(columnWidth)
#checking the longest item with looping in each row
for row in range(rowCount):
for column in range(columnCount):
if len(tableData[row][column]) > columnWidth[row]:
columnWidth[row] = len(tableData[row][column])
print(columnWidth)
for column in range(columnCount):
print()
for row in range(rowCount):
print(tableData[row][column].rjust(columnWidth[row]), end = ' ')