Skip to navigation
Create a sorted dict tree with python
02.03.17
def tree(): return defaultdict(tree) def dicts(t): return sortedcontainers.SortedDict({k: dicts(t[k]) for k in t}) t = tree() t['Animalia']['Chordata']['Mammalia']['Carnivora']['Felidae']['Felis']['cat'] t['Animalia']['Chordata']['Mammalia']['Carnivora']['Felidae']['Panthera']['lion'] t['Animalia']['Chordata']['Mammalia']['Carnivora']['Canidae']['Canis']['dog'] t['Animalia']['Chordata']['Mammalia']['Carnivora']['Canidae']['Canis']['coyote'] t['Plantae']['Solanales']['Solanaceae']['Solanum']['tomato'] t['Plantae']['Solanales']['Solanaceae']['Solanum']['potato'] t['Plantae']['Solanales']['Convolvulaceae']['Ipomoea']['sweet potato'] t = t = dicts(t) print(t)
https://gist.github.com/hrldcpr/2012250
Reply
Anonymous
Information Epoch 1732641699
Your system is just a path for moving data along.
Home
Notebook
Contact us