Created
October 29, 2015 21:02
-
-
Save 4poc/3e2243d3b9d57079ac2b to your computer and use it in GitHub Desktop.
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
foo = { | |
'nested': { | |
'dict': 42 | |
} | |
} | |
query = 'nested.dict' | |
# reduce: | |
from functools import reduce | |
value = reduce(lambda accu, key: accu[key], query.split('.'), foo) | |
assert(value == 42) | |
# ???: | |
accu = foo | |
for key in query.split('.'): | |
accu = accu[key] | |
assert(accu == 42) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment