Skip to content

Instantly share code, notes, and snippets.

@lucacervasio
Last active December 20, 2015 03:19
Show Gist options
  • Save lucacervasio/6062840 to your computer and use it in GitHub Desktop.
Save lucacervasio/6062840 to your computer and use it in GitHub Desktop.
build tree from dotted strings
#! /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