-1

I am trying to print outputs of each of the list next to each-other. Unfortunately I can only print the outputs of each list underneath one another.

tableData = [['apples', 'oranges', 'cherries', 'banana'],
            ['Alice', 'Bob', 'Carol', 'David'],
            ['dogs', 'cats', 'moose', 'goosee']]
            

for i in tableData:
    new_list_i = []
    word_list_i = []
    for word in i:
        new_list_i.append(len(word))
        word_list_i.append(word)
    #print(word_list_i)
    max_per_i = max(new_list_i)
    #print(max_per_i)
    
    for b in word_list_i:
        print((((b).rjust(max_per_i))))
        

How can I fix it? My format would be 4X3 and I am trying not to use an actual table, numpy or any other module.

Thanks in advance, I am sure it's something simple for someone with experience.

2 Answers2

0

Like this.

tableData = [['apples', 'oranges', 'cherries', 'banana'],
            ['Alice', 'Bob', 'Carol', 'David'],
            ['dogs', 'cats', 'moose', 'goosee']]

for i in range(len(tableData[0])):
    print(
            tableData[0][i],
            tableData[1][i],
            tableData[2][i],
            )
mama
  • 2,046
  • 1
  • 7
  • 24
0

If you are comfortable with converting to numpy array, consider this:

print(np.array(tableData).flatten())
Madhoolika
  • 396
  • 2
  • 8