Skip to content

Instantly share code, notes, and snippets.

@jwerak
Created February 16, 2015 17:35
Show Gist options
  • Save jwerak/72fa753f5e4234647835 to your computer and use it in GitHub Desktop.
Save jwerak/72fa753f5e4234647835 to your computer and use it in GitHub Desktop.
python list to dict
I've found this inspiring, but I would use this instead to add value to key:
def dot_set(s,v):
return reduce(lambda x,y: {y: x}, reversed(s.split('.')), v)
print dot_set('1.a.b.c', 'test')
do_set will return
{'1': {'a': {'b': {'c': 'test'}}}}
Then you can merge this dict using one of these techniques: http://stackoverflow.com/questions/11011756/is-there-any-pythonic-way-to-combine-two-dicts-adding-values-for-keys-that-appe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment