Given a flat list of (parent,child), create a hierarchical dictionary tree

Viewed 8635

I have a list with tuples that containing names. These names are parent and child names and I want to create a hierarchical dictionary tree with their names. For example I have the following list:

[('john','marry'),('mike','john'),('mike','hellen'),('john','elisa')]

and I want to create this:

{
    'mike':{
        'john':{
            'marry':{}
            'elisa':{}
         }
         'hellen':{}
        }
}
3 Answers
Related