Print list in table format in python

Blaise Delaney picture Blaise Delaney · Jun 24, 2013 · Viewed 51.4k times · Source

I am trying to print several lists (equal length) as columns of an table.

I am reading data from a .txt file, and at the end of the code, I have 5 lists, which I would like to print as columns separated but space.

Answer

arshajii picture arshajii · Jun 24, 2013

I'll show you a 3-list analog:

>>> l1 = ['a', 'b', 'c']
>>> l2 = ['1', '2', '3']
>>> l3 = ['x', 'y', 'z']
>>> for row in zip(l1, l2, l3):
...     print ' '.join(row)

a 1 x
b 2 y
c 3 z