Return to Snippet

Revision: 35601
at November 10, 2010 22:35 by magicrebirth


Initial Code
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']}

Initial URL
http://markmail.org/message/lcay3kerfvqlhkr2#query:python%20create%20tree%20from%20list+page:1+mid:pnheuqqy64vqhkjg+state:results

Initial Description
The resulting tree is represented through a dict where each father gets a key (with all the children as args)

Initial Title
From a list containing tree info, generare a tree in dict format

Initial Tags
list

Initial Language
Python