in scripts/internal/update_example_tables.py [0:0]
def format_table(headers, rows):
col_widths = [len(h) for h in headers]
for row in rows:
for i, cell in enumerate(row):
col_widths[i] = max(col_widths[i], len(cell))
header = "| " + " | ".join(f"{h:<{w}}" for h, w in zip(headers, col_widths)) + " |"
separator = "| " + " | ".join("-" * w for w in col_widths) + " |"
body = [
"| " + " | ".join(f"{cell:<{w}}" for cell, w in zip(row, col_widths)) + " |"
for row in rows
]
return "\n".join([header, separator] + body)