Print list in table format in python

后端 未结 5 1512
春和景丽
春和景丽 2020-12-31 18:27

I am trying to print several lists (equal length) as columns of an table.

I am reading data from a .txt file, and at the end of the code, I have 5 lists, which I wou

5条回答
  •  清酒与你
    2020-12-31 18:54

    You can use my package beautifultable . It supports adding data by rows or columns or even mixing both the approaches. You can insert, remove, update any row or column.

    Usage

    >>> from beautifultable import BeautifulTable
    >>> table = BeautifulTable()
    >>> table.column_headers = ["name", "rank", "gender"]
    >>> table.append_row(["Jacob", 1, "boy"])
    >>> table.append_row(["Isabella", 1, "girl"])
    >>> table.append_row(["Ethan", 2, "boy"])
    >>> table.append_row(["Sophia", 2, "girl"])
    >>> table.append_row(["Michael", 3, "boy"])
    >>> print(table)
    +----------+------+--------+
    |   name   | rank | gender |
    +----------+------+--------+
    |  Jacob   |  1   |  boy   |
    +----------+------+--------+
    | Isabella |  1   |  girl  |
    +----------+------+--------+
    |  Ethan   |  2   |  boy   |
    +----------+------+--------+
    |  Sophia  |  2   |  girl  |
    +----------+------+--------+
    | Michael  |  3   |  boy   |
    +----------+------+--------+
    

    Have fun

提交回复
热议问题