+ 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
7 Respostas
+ 4
here you go
for i in zip(*tableData):
print(*i)
+ 7
Choe, you did it! Great solution!
+ 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.
+ 4
Mine is here also.
https://code.sololearn.com/crCneht4aXte/?ref=app
+ 2
+ 1
Lamennais Try out first and then send the code.
+ 1
Thank you everyone for stepping into to assist me.