Printing Lists as Tabular Data

后端 未结 14 2374
小蘑菇
小蘑菇 2020-11-21 06:38

I am quite new to Python and I am now struggling with formatting my data nicely for printed output.

I have one list that is used for two headings, and a matrix that

14条回答
  •  后悔当初
    2020-11-21 07:23

    Some ad-hoc code:

    row_format ="{:>15}" * (len(teams_list) + 1)
    print(row_format.format("", *teams_list))
    for team, row in zip(teams_list, data):
        print(row_format.format(team, *row))
    

    This relies on str.format() and the Format Specification Mini-Language.

提交回复
热议问题