Last active
July 5, 2018 14:51
-
-
Save aizquier/ef229826754626ffc4b8b6e49c599b68 to your computer and use it in GitHub Desktop.
Python 2D array to HTML table
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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notice that this function assumes that the first row of the array correpond to the HTML table headers