Last active
December 20, 2015 03:19
-
-
Save lucacervasio/6062840 to your computer and use it in GitHub Desktop.
build tree from dotted strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
a = [ | |
'uno.due', | |
'uno.tre', | |
'uno.due.quattro' | |
] | |
root = {'uno': {}} | |
for it in a: | |
data = it.split(".") | |
cur = root | |
for part in data: | |
if part in cur: | |
cur = cur[part] | |
else: | |
cur[part] = {} | |
cur = cur[part] | |
print root |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment