each [
is a bracket. So it nominally just like nesting parenthesis:
mydict['description_long'] = another_dict['key1'][0][
'a_really_long_key']['another_long_key'][
'another_long_key3']['another_long_key4'][
'another_long_key4']
A more generic way might be to just do some metaprogramming and use a series of list comprehensions or iteration to expand child datastructures. For example, your child node can be found by following a path represented by the list:
keypath = ['key1', 0, 'a_really_long_key', 'another_long_key',
'another_long_key3','another_long_key4',
'another_long_key4']
so you reference your final node by something like:
def resolve_child(root, path):
for e in path:
child = root[e]
root = child
return child
mydict['description_long'] = resolve_path(another_dict, keypath)
Or if you want to be all functional (Note that reduce()
is moved to functools
in Py3K):
mydict['description_long'] = reduce(lambda p,c: p[c], keypath, another_dict)
It is usually rare that you have to explicitly reference a deeply nested structure like that; usually the structure is being instantiated by some function, like json.parse or lxml.objectify