You really just need to get the labels for the rows and columns. From there, it's just a few for
loops:
from __future__ import print_function
import itertools
reservoir = {
('a', 'b'): 2,
('a', 'c'): 3,
('b', 'a'): 1,
('b', 'c'): 3,
('c', 'a'): 1,
('c', 'b'): 2,
('c', 'd'): 5
}
fields = sorted(list(set(itertools.chain.from_iterable(reservoir))))
print(' ', *fields)
for row in fields:
print(row, end=' ')
for column in fields:
print(reservoir.get((row, column), 0), end=' ')
print()
Your table will start getting ugly when the cells get more than one digit, so I'll leave that to you to figure out. You'll just need to find the maximal length of the field for each column before printing them.