Matrix display with text

Hi All,

is there a nice way similar to “matrix display” that could show also text.
Splitting up the list below into 5 panels isn’t a fancy way of showing results.
Preferably without using third-party plugins like Human.

[‘detail’, ‘Orginal Area’, ‘New Area’, ‘Area difference’, ‘distance’, 0.0, 858922.282672682, 858923.8709535187, ‘0.0%’, 2.5139757993742657, 1.0, 474914.8516458379, 474913.53620281606, ‘-0.0%’, 65.99713493501264, 2.0, 446538.48334372113, 446597.82309198694, ‘0.0%’, 8.090157128402202]

Best regards

String formatting, e.g.

l = ['detail', 'Orginal Area', 'New Area', 'Area difference', 'distance', 0.0, 858922.282672682, 858923.8709535187, '0.0%', 2.5139757993742657, 1.0, 474914.8516458379, 474913.53620281606, '-0.0%', 65.99713493501264, 2.0, 446538.48334372113, 446597.82309198694, '0.0%', 8.090157128402202]


nested_list = list(zip(*[iter(l)]*5))

widths = [len(x) for x in nested_list[0]]

s = ' | '.join(x for x in nested_list[0]) + '\n'

for row in nested_list[1:]:
    s += ',  '.join('%{}.{}s'.format(width,width) % x for (x, width) in zip(row, widths))
    s += '\n'

print(s)

gives:

detail | Orginal Area | New Area | Area difference | distance
   0.0,  858922.28267,  858923.8,             0.0%,  2.513975
   1.0,  474914.85164,  474913.5,            -0.0%,  65.99713
   2.0,  446538.48334,  446597.8,             0.0%,  8.090157

I like the tabulate module for printing tables:

# r: tabulate

from tabulate import tabulate


l = ['detail', 'Orginal Area', 'New Area', 'Area difference', 'distance', 0.0, 858922.282672682, 858923.8709535187, '0.0%', 2.5139757993742657, 1.0, 474914.8516458379, 474913.53620281606, '-0.0%', 65.99713493501264, 2.0, 446538.48334372113, 446597.82309198694, '0.0%', 8.090157128402202]
nested_list = list(zip(*[iter(l)]*5))

print(tabulate(
    nested_list, headers="firstrow", stralign="right",
    floatfmt=[".0f", ".1f", ".1f", "f", ".4f"]
))

  detail    Orginal Area    New Area    Area difference    distance
--------  --------------  ----------  -----------------  ----------
       0        858922.3    858923.9               0.0%      2.5140
       1        474914.9    474913.5              -0.0%     65.9971
       2        446538.5    446597.8               0.0%      8.0902
3 Likes

Awesome, thanks both of you!
100% spot on what I needed