I have a list of lists in a file:
[ [ \'aaaaa\', \'bbb\',\'ccccccccc\' ], [ \'aaaaa\', \'bbbbbb\',\'cccccc\' ], [ \'aaa\', \'bbb\',\'ccccccccc\' ] ]
Tested with Python2.7:
lst = [ [ 'aaaaa', 'bbb','ccccccccc' ], [ 'aaaaa', 'bbbbbb','cccccc' ], [ 'aaa', 'bbb','ccccccccc' ] ]
widths = [max(len(j) for j in i) for i in zip(*lst)]
s = ''.join('{{:<{}}}'.format(w+2) for w in widths)
for v in lst:
print(s.format(*v))
Prints each column aligned to max width of string inside this column + 2 extra characters:
aaaaa bbb ccccccccc
aaaaa bbbbbb cccccc
aaa bbb ccccccccc