user3132352 user3132352 - 2 months ago 14
HTML Question

Python html table layout

I'm using the

from I have a list with this structure:
a = [['a'], ['b'], ['c']]
. By using the HTML.table my table is only with one column but I want them to be two. How I can do this?


Use something like: a = [['a', 'a2'], ['b', 'b2'], ['c', 'c2']]

Your outer list makes the rows, the inner lists make the columns.

You can use itertools to regroup your lists:

import itertools
b = list(itertools.izip_longest(fillvalue='', *([itertools.chain(*a)] * 2)))

(sets b to [('a', 'b'), ('c', '')])

That 2 is how many elements you want per sublist, i.e. how many columns you want in this case. fillvalue is the value it fills in when it runs out; default is None.