Skip to content

Instantly share code, notes, and snippets.

@ohmerhe
Forked from m0neysha/pylist-to-markdown.py
Created July 25, 2019 09:07
Show Gist options
  • Save ohmerhe/b8ed8113cc20ed8bc9193c12b3a315c4 to your computer and use it in GitHub Desktop.
Save ohmerhe/b8ed8113cc20ed8bc9193c12b3a315c4 to your computer and use it in GitHub Desktop.
Python lists to markdown table
def make_markdown_table(array):
""" Input: Python list with rows of table as lists
First element as header.
Output: String to put into a .md file
Ex Input:
[["Name", "Age", "Height"],
["Jake", 20, 5'10],
["Mary", 21, 5'7]]
"""
markdown = "\n" + str("| ")
for e in array[0]:
to_add = " " + str(e) + str(" |")
markdown += to_add
markdown += "\n"
markdown += '|'
for i in range(len(array[0])):
markdown += str("-------------- | ")
markdown += "\n"
for entry in array[1:]:
markdown += str("| ")
for e in entry:
to_add = str(e) + str(" | ")
markdown += to_add
markdown += "\n"
return markdown + "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment