title: Python: create nested dictionary from parent-child mapping
body: <p>I have child-parent mapping as follows:</p>
  
  <pre><code>{4:6,
   6:9,
   7:6,
   5:6,
   8:9,
   11:9,
   10:9,
   12:10,
   13:10}
  </code></pre>
  
  <p>I want to create following nested dictionary using above:</p>
  
  <pre><code>{"id":9,
   "children":[
               {"id":6,
                "children":[
                            {"id":4,
                             "children":[]},
                            {"id":5,
                             "children":[]},
                            {"id":7,
                             "children":[]},
                           ]
                },
                {"id":10,
                "children":[
                            {"id":12,
                             "children":[]},
                            {"id":13,
                             "children":[]},
                           ]
                },
                {"id":11,
                "children":[]
                },
                {"id":8,
                "children":[]
                }
                ]
  }
  </code></pre>
  
  <p>I am able to figure out how I can do it if in place of having keys as "id" and values as 9,6,etc , I have values as keys. Please help me with the above format.  </p>