def flatten_dict(dic, parent_key='<STR_LIT>', sep='<STR_LIT:.>'):
items = []<EOL>for key, value in dic.items():<EOL><INDENT>new_key = parent_key + sep + key if parent_key else key<EOL>if isinstance(value, collections.MutableMapping):<EOL><INDENT>items.extend(flatten_dict(value, new_key, sep=sep).items())<EOL><DEDENT>elif isinstance(value, list):<EOL><INDENT>for idx, elt in enumerate(value):<EOL><INDENT>items.extend(<EOL>flatten_dict(elt, new_key + sep + str(idx), sep=sep).items()<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>items.append((new_key, value))<EOL><DEDENT><DEDENT>return dict(items)<EOL>
Flatten sub-keys of a dictionary