The goal of this program was to take in a nested list called tableData and write a function that displays organized columns that are right-justified. The function works for the code but I would like to get some feedback or to know if I can be done more efficiently for problems in the future.
apples Alice dogs
oranges Bob cats
cherries Carol moose
banana David goose
tableData = [['apples','oranges','cherries','banana'],
['Alice','Bob','Carol', 'David'],
['dogs', 'cats','moose','goose']]
def printTable():
colWidths = [0]* len(tableData)
one = []
two = []
three = []
for i in range(len(tableData)):
colWidths[i] = tableData[i]
place = tableData[i]
for x in range(len(tableData[i])):
spot = colWidths
if len(one) < len(place):
one.append(colWidths[i][x])
elif len(two) < len(place):
two.append(colWidths[i][x])
elif len(three) < len(place):
three.append(colWidths[i][x])
for i in range(len(one)):
print((one[i]+' ' +two[i]+ ' ' +three[i]).center(20,))
printTable()
tabulatemodule (github.com/astanin/python-tabulate). It's included in Anaconda, and available in the Debian repositories if you don't want to use pip.