Example input:
[('b', 'c', 4),
('l', 'r', 5),
('i', 'a', 6),
('c', 't', 7),
('a', '$', 8),
('n', '$', 9)]
[0] contains the vertical heading, [1] contains the horizontal heading.
Example output:
c r a t $ $
b 4
l 5
i 6
c 7
a 8
n 9
Note: given enough tuples the entire table could be filled 😛
How do I format output as a table in Python using [preferably] one line of code?
Here’s an answer for your revised question:
Or, if that’s too long for you, try this:
Both have the following output:
Here’s the kernel of what you want (no reader row or header column)
It uses a nested list comprehension over
iandjto generate the numbersi+j, thenstr.rjust()to pad all fields to three characters in length, and finally somestr.join()s to put all the substrings together.