Customised output using 'for loop' | Sololearn: Learn to code for FREE!


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

3/23/2020 5:06:34 PM


7 Answers

New Answer


here you go for i in zip(*tableData): print(*i)


Choe, you did it! Great solution!


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.


Mine is here also.


try this:


Lamennais Try out first and then send the code.


Thank you everyone for stepping into to assist me.