title: Python nested Dictionary: Count the maximum number of keys for a parent key
body: <p>Probably my question wordings are not quite correct. Here is the question:</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>import jinja2
  import pprint
  
  
  dict = {'PRI_KEY_1': {'SEC_KEY_1': {'KEY_1': 'abcd',
                                      'KEY_2': 'wef'}},
          'PRI_KEY_2': {'SEC_KEY_2': {'KEY_3': 'cwc API',
                                      'KEY_4': 'r34f',
                                      'KEY_5': 'f4f-ef',
                                      'KEY_6': 'dse',
                                      'KEY_7': '78ik',
                                      'KEY_8': 'k9k'},
                        'SEC_KEY_1': {'KEY_9': 'kk7 API',
                                      'KEY_10': '9u',
                                      'KEY_11': 'gtgr-45gr',
                                      'KEY_12': 'ggrer',
                                      'KEY_13': 'nmb',
                                      'KEY_14': 'ekj',
                                      'KEY_15': 'das3',
                                      'KEY_16': '5lusf',
                                      'KEY_17': '3rt5hf',
                                      'KEY_18': 'f4gth',
                                      'KEY_19': 'dfghtgr',
                                      'KEY_20': 'chy',
                                      'KEY_21': 'xdvgrw'}}}
  temp_list = []
  
  for key in dict['PRI_KEY_2']:
      temp_list.append(len(dict['PRI_KEY_2'][key]))
  
  print('Rowspan needed for PRI_KEY_2:',max(temp_list))
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>Rowspan needed for PRI_KEY_2: 13
  </code></pre>
  
  <p><strong>Question:</strong>
  Above code works. However, is there a better way to achieve this? 
  The reason being, I am creating an html table using <code>jinja2</code> where I need to define the <code>rowspan</code> for <code>PRI_KEY_2</code> considering the maximum keys its child keys has so that the table will <em>look like</em> a table.</p>
  
  <p>BTW, My Dict has 100+ <code>PRI_KEY_*</code> and many more under their child, grand child keys.</p>