I'm trying to construct some presentable tables in python by combining data from two lists.
As an example, let's say I recorded the contestants in a race and I had the name, time and some other arbitrary measurement for each person:
headings = ['Name:','Time:','Awesomeness:']
info = [('Foo', 15.24242, 100), ('Bar', 421.333, 10), ('Pyth the Python', 3.333, 9000)]
I've applied some formatting by making the function neatomatic9000
to make the table's columns indented properly.
def neatomatic9000(something):
print("{0: <20}".format(something), end = '')
for i in headings:
neatomatic9000(i)
print('\n')
for j in info:
for k in j:
neatomatic9000(k)
print('\n')
My table is printed like so:
Name: Time: Awesomeness:
Foo 15.24242 100
Bar 421.333 10
Pyth the Python 3.333 9000
Which looks okay, but I'm trying to make the table with the headings as a column on the left - essentially I'm trying to transpose it to look like this:
Name: Foo Bar Pyth the Python
Time: 15.24242 421.333 3.333
Awesomeness: 100 10 9000
EDIT: On another note, python infuriatingly seems to lack a check to see if something is a number regardless if its a float or an integer. I can't seem to incorporate a condition to check if an entry is a number, then round it to two decimal places with "{:.2f}".format(k)