/ Published in: Python
The resulting tree is represented through a dict where each father gets a key (with all the children as args)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
source_list =[ {'title': 'Project', 'parent':'root'}, {'title': 'Geometry', 'parent':'root'}, {'title': 'Soil', 'parent':'root'}, {'title': 'Geometries', 'parent':'Project'}, {'title': 'Verticals', 'parent':'Project'}, {'title': 'Points', 'parent':'Geometry'}, {'title': 'Layers', 'parent':'Geometry'}, {'title': 'Water', 'parent':'Geometry'}, {'title': 'Soiltypes', 'parent':'Soil'}] imd=dict() for d in source_list: par=d['parent'] v=d['title'] try: imd[par].append(v) except: imd[par]=[v] imd {'Project': ['Geometries', 'Verticals'], 'Geometry': ['Points', 'Layers', 'Water'], 'root': ['Project', 'Geometry', 'Soil'], 'Soil': ['Soiltypes']}