Printing Lists as Tabular Data

后端 未结 14 2068
小蘑菇
小蘑菇 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:09

    To create a simple table using terminaltables

    Open the terminal or your command prompt and run pip install terminaltables You can print and python list as the following

    from terminaltables import AsciiTable
    
    l = [
      ['Head', 'Head'],
      ['R1 C1', 'R1 C2'],
      ['R2 C1', 'R2 C2'],
      ['R3 C1', 'R3 C2']
    ]
    
    table = AsciiTable(l)
    
    print(table.table)
    

    They have other cool tables don't forget to check them out. Just google their library.

    Hope that helps :100:!

提交回复
热议问题