def pp_list(out, table, labels):
    assert 0 < len(labels)
    # XXX Consider quotation/escapes.
    colwidths = [len(label) for label in labels]
    for row in table:
        for colno, v in enumerate(row):
            # XXX Consider quotation/escapes.
            # XXX Combining characters?
            colwidths[colno] = max(colwidths[colno], len(unicode(v)))
    first = True
    for colno, label in enumerate(labels):
        if first:
            first = False
        else:
            out.write(' | ')
        # XXX Quote/escape.
        out.write('%*s' % (colwidths[colno], label))
    out.write('\n')
    first = True
    for colno, label in enumerate(labels):
        if first:
            first = False
        else:
            out.write('-+-')
        # XXX Quote/escape.
        out.write('%s' % ('-' * colwidths[colno]))
    out.write('\n')
    for row in table:
        first = True
        for colno, v in enumerate(row):
            if first:
                first = False
            else:
                out.write(' | ')
            # XXX Quote/escape.
            out.write('%*s' % (colwidths[colno], unicode(v)))
        out.write('\n')
dataset/ETHPy150Open probcomp/bayeslite/shell/src/pretty.py/pp_list/original