Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
You can’t perform that action at this time.