from typing import OrderedDict


def dict_to_table(dct, titles=('col1', 'col2'), margin=3, sort=True):
    """
    Formats a dict where key:val is str:str into a two column table.
    """
    if sort:
        dct = OrderedDict({key: dct[key] for key in sorted(dct.keys())})
    col1width = max([len(str(s)) for s in dct.keys()] + [len(titles[0])])
    col2width = max([len(str(s)) for s in dct.values()] + [len(titles[1])])
    width = col1width + col2width + margin
    baseline = ('%%-%ds' % col1width) + ' ' * margin + ('%%-%ds' % col2width)
    output = '\n' + baseline % titles + '\n' + '-' * width
    for key, val in dct.items():
        output += '\n' + (baseline % (key, val))
    return output