user3132352 user3132352 - 1 year ago 97
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download