summaryrefslogtreecommitdiff
path: root/Chap6PracPrintTable.py
diff options
context:
space:
mode:
authormlot <petri-rush-curvy@duck.com>2025-06-06 13:40:57 -0400
committermlot <petri-rush-curvy@duck.com>2025-06-06 13:40:57 -0400
commit75a42ec54dbf721caa659ddf02c1f46fc2cb4bef (patch)
tree84be794a2481e356a7784557a6f9fb6fbf29cfdd /Chap6PracPrintTable.py
initial commit for archivingHEADmain
Diffstat (limited to 'Chap6PracPrintTable.py')
-rw-r--r--Chap6PracPrintTable.py22
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)
+