I am going through automate the boring stuff, diong chapter 6 first practice problems:
tableData = [['apples', 'oranges', 'cherries', 'banana'],
['Alice', 'Bob', 'Carol', 'David'],
['dogs', 'cats', 'moose', 'goose']]
I would like to tried the following output without using zip function or map cause I am forcing myself to get deeper understanding regarding list manipulation without using those methods.
apples | Alice | dogs
oranges| Bob | cats
cherries | Carol | moose
banana | David | goose
So far I have tried the following:
for i in range(len(tableData[0])):
print(' '.join(subLst[i] for subLst in tableData))
which does give me intended output, but the range parameter I used feels kinda brutish, so is there any other way I could solve this problem ??
print(*map(' '.join, zip(*tableData)), sep='\n')is almost irresistible, again assuming common length of sublists. I do want to know why David missed out on plurals though.