0

I need some explanation

print("bai tap list hay" ) string="" tableData=[['apples','oranges','cherries','banana'], ['Alice','Bob','Carol','David'], ['dogs','cats','moose','goose']] for i in range(len(tableData)+1): print(i) for j in range(len(tableData)): print(i) string+=tableData[j][i] + " " #I do not understand this part of the code "string+=tableData[j][i]+ " " string+="\n" print(string)

4th Jan 2019, 6:17 PM
Khai123
Khai123 - avatar
1 Answer
+ 1
i counts from 0 to 3 j counts from 0 to 2 the line you don't understand adds words from the list to the output string with a blank. The first word is apples as it is stored in tableData[0][0]. The next ones are Alice [1][0] and dogs [2][0]. Then, the j loop finishes and the new line gets added to the string. The next line is oranges [0][1], Bob [1][1], and cats [2][1].
5th Jan 2019, 2:49 AM
John Wells
John Wells - avatar