title: How to create an html table by looping through python nested dictionary
body: <p>I currently have a nested dictionary object in Python that I want to loop through to essentially create an html table. I already know the basics on what to do, but need help with determining the number of rows each column should span. Let me explain more with an example:</p>
  
  <pre><code>Input:
  
  {  
     "system":{  
        "System Apps":{  
           "SystemEnv":[  
             'App Test',
              'App Memory',
               'App Test']
  
          "SystemEnv2":{  
           "System Test":[  
             'App Test']
           }},
           "System Memory":{  
              "Memeory Test":[  
                 'Memory Func',
                 'Apes Test']
              }
           }
        }
     }
  }
  </code></pre>
  
  <p>Output:
  <a href="https://i.stack.imgur.com/VCxSJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VCxSJ.png" alt="Html Table Output"></a></p>
  
  <p>The problem lies in putting the rowspan attribute and having the correct number of rows to span. I understand that it is the number of children the parent has, but I can seem to figure out how to code it.</p>
  
  <p>Also second priority, but if someone sees a more efficient way of doing this, please let me know.</p>
  
  <pre><code> for level1 in dictObj:
          html += "&lt;tr&gt;"
          html += '&lt;td&gt;{}&lt;/td&gt;'.format(level1)
          for level2 in dictObj[level1]:
              if not first_run:
                  html += "&lt;tr&gt;"
              html += '&lt;td&gt;{}&lt;/td&gt;'.format(level2)
              first_run = True
              for level3 in dictObj[level1][level2]:
                  if not first_run:
                      html += "&lt;tr&gt;"
                  html += '&lt;td&gt;{}&lt;/td&gt;'.format(level3)
                  first_run = True
                  for app in dictObj[level1][level2][level3]:
                      if not first_run:
                          html += "&lt;tr&gt;"
                      first_run = True
                      for test in dictObj[level1][level2][level3][app]:
                          if not first_run:
                              html += "&lt;tr&gt;"
                          html += '&lt;td&gt;{}&lt;/td&gt;'.format(test)
                          html += '&lt;td&gt;{}&lt;/td&gt;'.format(app)
                          html += '&lt;td&gt;{}&lt;/td&gt;'.format('mb')
                          html += '&lt;td&gt;{}&lt;/td&gt;'.format(1)
                          html += '&lt;/tr&gt;'
                          first_run = False
  </code></pre>