From 75a42ec54dbf721caa659ddf02c1f46fc2cb4bef Mon Sep 17 00:00:00 2001 From: mlot Date: Fri, 6 Jun 2025 13:40:57 -0400 Subject: initial commit for archiving --- Chap6PracPrintTable.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Chap6PracPrintTable.py (limited to 'Chap6PracPrintTable.py') 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) + -- cgit