I'd like to print a list of lists where the width of each string is fixed into the max length of its corresponding column. Here is what I have tried.
lists = [['abcde', u'一二三四五'],
[u'六七八九十零', 'fghij']]
# calculate the maximum length of each column
column_max_len = [max(len(item) for item in t) for t in zip(*lists)] # [6, 5]
# format print
for row in lists:
s = '\t'.join(['{value:<{width}}'.format(value=row[idx].encode('utf-8'), width=column_max_len[idx])
for idx, item in enumerate(row)])
print(s)
The output is,
abcde 一二三四五
六七八九十零 fghij
My expected result is,
abcde 一二三四五
六七八九十零 fghij