Created
April 15, 2022 10:54
-
-
Save JosephTLyons/c7a5b5744a17c92cd30a3072509ad5dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_markdown_table_lines(rows): | |
if not rows: | |
return [] | |
create_row_string = lambda row: f"| {' | '.join(row)} |" | |
headers = list(rows[0].keys()) | |
separators = ["-"] * len(headers) | |
lines = [ | |
create_row_string(headers), | |
create_row_string(separators) | |
] | |
for row in rows: | |
row_values = [str(row[header]) for header in headers] | |
lines.append(create_row_string(row_values)) | |
return lines | |
def create_table_section(table_description_text, rows): | |
if not rows: | |
return [] | |
row_count = len(rows) | |
lines = [f"{table_description_text} ({row_count})"] + create_markdown_table_lines(rows) | |
return lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment