'How to create embedded tables in docx using python (or template marks)?

Lets suppose I have data that looks something like this:

{
'list_of_effects': ['K1_W01', 'K1_W02', 'K1_W03', 'K1_W04'], 
'classes': [
{'effects': {'K1_W04', 'K1_W01'}, 'class': 'Algorithms', 'semester': [3]}, 
{'effects': {'K1_W01'}, 'class': 'Algebra', 'semester': [1]}, 
{'effects': {'K1_W03'}, 'class': 'Analysis', 'semester': [1]}
]}

And I need to create a dynamic table in docx that looks something like this (this is small size table, it can be much bigger depending on mentioned data):

|    Name of class          |'K1_W01'|'K1_W02'|'K1_W03'|'K1_W04'|  
|___________________________|________|________|________|________|
|          | Algebra        |    +   |        |        |        | 
|Semester 1|________________|________|________|________|________|
|          | Analysis       |        |        |   +    |        |
|__________|________________|________|________|________|________|
|Semester 3| Algorithms     |   ++   |        |        |   +    | 
|__________|________________|________|________|________|________| 
|Sum                        |   3    |    0   |   1    |   1    | 
|___________________________|________|________|________|________|

                       

I need to put it inside docx template, but with using template language is really impossible to generate it inside docx as it is desired. What is the most clever, and easiest way to create that kind of tables? I am looking for other ideas, but it needs to be cenverted to pdf.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source