diff options
author | mlot <petri-rush-curvy@duck.com> | 2025-06-06 13:40:57 -0400 |
---|---|---|
committer | mlot <petri-rush-curvy@duck.com> | 2025-06-06 13:40:57 -0400 |
commit | 75a42ec54dbf721caa659ddf02c1f46fc2cb4bef (patch) | |
tree | 84be794a2481e356a7784557a6f9fb6fbf29cfdd /Chap6PracPrintTable.py |
Diffstat (limited to 'Chap6PracPrintTable.py')
-rw-r--r-- | Chap6PracPrintTable.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Chap6PracPrintTable.py b/Chap6PracPrintTable.py new file mode 100644 index 0000000..83b20c1 --- /dev/null +++ b/Chap6PracPrintTable.py @@ -0,0 +1,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) + |