I have a list of dicts that looks something like this:
list = [{'parent': u'#5963','id': 5962},{'parent': u'','id': 5963},
{'parent': u'#5963', 'id': 5964}, {'parent': u'#5966', 'id': 5967},
{'parent': u'#5963','id': 5966}, {'parent': u'#5962','id': 5968} ]
The actual dicts are a bit more complex - they have more keys and values.
As you can see - every dict has a 'parent' key, which tells us elements parent's id and an 'id' key.
Now the question is: is it possible to build a new list (or sort this one) in a way that all dicts are placed in a parent-child way?
So the new dict will be:
[{'parent': u'','id': 5963},{'parent': u'#5963','id': 5962},
{'parent': u'#5962','id': 5968}, {'parent': u'#5963', 'id': 5964},
{'parent': u'#5963','id': 5966}, {'parent': u'#5966', 'id': 5967} ]
PS: There maybe no root elements (elements with 'parent' key = '')
PPS: Parent element may have more than 1-2 levels of children