Skip to content

Instantly share code, notes, and snippets.

@hallazzang
Created April 21, 2018 19:33
Show Gist options
  • Save hallazzang/9ebbca0a234ec5bea961e15176a6c19a to your computer and use it in GitHub Desktop.
Save hallazzang/9ebbca0a234ec5bea961e15176a6c19a to your computer and use it in GitHub Desktop.
table_structure = [
[('A', 3, 1), ('B', 1, 2), ('C', 3, 1)],
[('D', 1, 1), ('E', 2, 1)],
[('F', 2, 1)],
[('G', 1, 2), ('H', 1, 2)],
]
total_cols = sum(x[2] for x in table_structure[0])
table = [[None]*total_cols for _ in range(len(table_structure))]
for row_idx, row in enumerate(table_structure):
col = 0
while table[row_idx][col] is not None:
col += 1
for cell in row:
text, rowspan, colspan = cell
for r in range(rowspan):
for c in range(colspan):
table[row_idx+r][col+c] = text
col += colspan
for row in table:
print(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment