Created
February 16, 2015 17:35
-
-
Save jwerak/72fa753f5e4234647835 to your computer and use it in GitHub Desktop.
python list to dict
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
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