I'm trying to display a nested list as a column. So the data that I'm working with is:
tableData = [['apples', 'oranges', 'cherries', 'banana'], ['Alice', 'Bob', 'Carol', 'David'], ['dogs', 'cats', 'moose', 'goose']]
which I want to display as
apples Alice dogs
oranges Bob cats
cherries Carol moose
banana David goose
so that the entries are right aligned. I've had a look at Create nice column output in python but I'm not able to implement it for a similar outcome. The code that I have so far is:
tableData = [['apples', 'oranges', 'cherries', 'banana'], ['Alice', 'Bob', 'Carol', 'David'], ['dogs', 'cats', 'moose', 'goose']]
total_len= [[] for x in range(len(tableData))]
longest_string = []
for y1 in range(0, len(tableData)):
for y2 in range(0, len(tableData[y1])):
total_len[y1].append(len(tableData[y1][y2]))
for y1 in range(0, len(total_len)):
longest_string.append(max(total_len[y1]))
for y1 in range(len(tableData)):
for y2 in range(len(tableData[y1])):
print("".join(tableData[y1][y2].rjust(longest_string[y1])))