Skip to content

Instantly share code, notes, and snippets.

@aizquier
Last active July 5, 2018 14:51
Show Gist options
  • Save aizquier/ef229826754626ffc4b8b6e49c599b68 to your computer and use it in GitHub Desktop.
Save aizquier/ef229826754626ffc4b8b6e49c599b68 to your computer and use it in GitHub Desktop.
Python 2D array to HTML table
def array2htmltable(data):
q = "<table>\n"
for i in [(data[0:1], 'th'), (data[1:], 'td')]:
q += "\n".join(
[
"<tr>%s</tr>" % str(_mm)
for _mm in [
"".join(
[
"<%s>%s</%s>" % (i[1], str(_q), i[1])
for _q in _m
]
) for _m in i[0]
]
])+"\n"
q += "</table>"
return q
@aizquier
Copy link
Author

aizquier commented Jul 5, 2018

Notice that this function assumes that the first row of the array correpond to the HTML table headers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment