The Student Room Group

Tables in Python?

how.jpg
How to create table like this in Python?
Original post by varsketis
how.jpg
How to create table like this in Python?


Print it out line by line, adding spaces where necessary to keep the columns in line.
Reply 2
Original post by morgan8002
Print it out line by line, adding spaces where necessary to keep the columns in line.


Any way to make the lines in bold?
Ty btw.
Original post by varsketis
Any way to make the lines in bold?
Ty btw.


Tbh I'm not sure. I think it depends on what terminal you're using. Doing a Google search for "python print bold" or similar will give you several methods, which may work depending on your terminal.
Reply 4
Original post by morgan8002
Tbh I'm not sure. I think it depends on what terminal you're using. Doing a Google search for "python print bold" or similar will give you several methods, which may work depending on your terminal.


Thanks :smile:
If you're still needing help, here's a way to do it which I found from stack overflow:

teams_list = ["Man Utd", "Man City", "T Hotspur"]
data = [[1, 2, 1],
[0, 1, 0],
[2, 4, 2]]
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))

Quick Reply

Latest

Trending

Trending