title: grouping elements of a flattened dictionary into a sub list
body: <p>I have a flattened json (flattened using flatten json library). I have to now group them</p>
  
  <pre><code>{   'persons_0_address_building': '710',
      'persons_0_address_coord': '[123, 40]',
      'persons_0_address_street': 'Avenue 1',
      'persons_0_address_zipcode': '12345',
      'persons_0_cuisine': 'Chinese',
      'persons_0_grades_0_date': '2014-03-03T00:00:00.000Z',
      'persons_0_grades_0_grade': 'A',
      'persons_0_grades_0_score_x': 1,
      'persons_0_grades_0_score_y': 2,
      'persons_0_grades_1_date': '2011-11-23T00:00:00.000Z',
      'persons_0_grades_1_grade': 'A',
      'persons_0_grades_1_score_x': 11,
      'persons_0_grades_1_score_y': 22,
      'persons_0_id': '4d322fa8f552',
      'persons_0_name': 'Shash'
  
  }
  </code></pre>
  
  <p>The desired result is as follows. </p>
  
  <pre><code>person_address = 
  [
     {
      'building': '710',
      'coord': '[123, 40]',
      'street': 'Avenue 1',
      'zipcode': '12345',
      'id': '4d322fa8f552'
     }
  ]
  person = 
  
  [{
      'cuisine': 'Chinese',
      'id': '4d322fa8f552',
      'name': 'Shash'
  
  }]
  </code></pre>
  
  <p>The basic idea is after grouping I can load each of the lists into a flat file.</p>
  
  <p><strong>What all I have tried so far:</strong> </p>
  
  <ol>
  <li>Taking each of the key and checking for <code>_</code>,  sorting them, and taking the result. This approach had lots of issues. </li>
  <li>Tried using <code>defaultdict</code> but i am not able to even remotely get to this. </li>
  </ol>
  
  <p>Is there any better way to get to this. </p>