def pretty_print(fields, matrix):
    # type: (List[str], List[List[Any]]) -> None
    '''Pretty prints a matrix of data.'''
    contents = [fields] + matrix
    contents = [[str(i) for i in row] for row in contents]
    # Pretty print rows
    # Find maximum length for each column in the context matrix
    lens = [max([len(item) for item in col]) for col in zip(*contents)]
    # Prepare formatting string for column sizes
    fmt = ' | '.join('{{:{}}}'.format(x) for x in lens)
    # Apply formatting to each row in the context string
    table = [fmt.format(*row) for row in contents]
    # Add header separator
    table.insert(1, '-' * len(table[0]))
    # Join lines with newline
    result = '\n'.join(table)

    print result
Pretty prints a matrix of data.
scripts/query_db.py