+ 1

Customised output using 'for loop'

I'm trying to write a code that converts the list below(tableData) into the output on the bottom: tableData = [['apples', 'oranges', 'cherries', 'banana'], ['Alice', 'Bob', 'Carol', 'David'], ['dogs', 'cats', 'moose', 'goose']] Required output format: apples Alice dogs oranges Bob cats cherries Carol moose banana David goose existing code: tamanho_da_lista = len(tableData) contagem = 1 lista =[] listagem = [] for a in tableData: lista.append(a) for n in lista: for b in n: print (b) #break break output: apples oranges cherries banana

23rd Mar 2020, 5:06 PM
Lamennais
7 Answers
+ 4
here you go for i in zip(*tableData): print(*i)
23rd Mar 2020, 6:52 PM
Choe
Choe - avatar
+ 7
Choe, you did it! Great solution!
23rd Mar 2020, 8:18 PM
Lothar
Lothar - avatar
+ 6
The input data is a nested list of lists. so you have to use the 3 inner lists like they were independent, and put them together with zip() to the desired output.
23rd Mar 2020, 6:15 PM
Lothar
Lothar - avatar
23rd Mar 2020, 9:32 PM
Oluwafemi
Oluwafemi - avatar
23rd Mar 2020, 5:43 PM
Gabriel Ilie
Gabriel Ilie - avatar
+ 1
Lamennais Try out first and then send the code.
23rd Mar 2020, 5:19 PM
Taranjeet
Taranjeet - avatar
+ 1
Thank you everyone for stepping into to assist me.
23rd Mar 2020, 7:47 PM
Lamennais