def flatten(d, parent_key='<STR_LIT>', sep='<STR_LIT:_>'):
items = []<EOL>for k, v in d.items():<EOL><INDENT>new_key = parent_key + sep + k if parent_key else k<EOL>if isinstance(v, collections.MutableMapping):<EOL><INDENT>items.extend(flatten(v, new_key, sep=sep).items())<EOL><DEDENT>else:<EOL><INDENT>items.append((new_key, v))<EOL><DEDENT><DEDENT>return dict(items)<EOL>
Flatten keys in a dictionary
Example:
flatten({'a': 1, 'c': {'a': 2, 'b': {'x': 5, 'y' : 10}}, 'd': [1, 2, 3]})
=> {'a': 1, 'c_a': 2, 'c_b_x': 5, 'd': [1, 2, 3], 'c_b_y': 10}
:param d:  Dictionary to flatten
:param sep: Separator between keys
:param parent_key: Key to merge with