def flatten_dict(d, prefix='<STR_LIT>', sep='<STR_LIT:.>'):
def apply_and_resolve_conflicts(dest, item, prefix):<EOL><INDENT>for k, v in flatten_dict(item, prefix=prefix, sep=sep).items():<EOL><INDENT>new_key = k<EOL>i = <NUM_LIT:2><EOL>while new_key in d:<EOL><INDENT>new_key = '<STR_LIT>'.format(key=k, sep=sep, index=i)<EOL>i += <NUM_LIT:1><EOL><DEDENT>dest[new_key] = v<EOL><DEDENT><DEDENT>for key in list(d.keys()):<EOL><INDENT>if any(unicode(prefix)):<EOL><INDENT>new_key = u'<STR_LIT>'.format(p=prefix, key=key, sep=sep)<EOL><DEDENT>else:<EOL><INDENT>new_key = key<EOL><DEDENT>if isinstance(d[key], (dict, collections.Mapping)):<EOL><INDENT>apply_and_resolve_conflicts(d, d.pop(key), new_key)<EOL><DEDENT>elif isinstance(d[key], six.string_types):<EOL><INDENT>d[new_key] = d.pop(key)<EOL><DEDENT>elif isinstance(d[key], (list, collections.Mapping)):<EOL><INDENT>array = d.pop(key)<EOL>for i in range(len(array)):<EOL><INDENT>index_key = '<STR_LIT>'.format(key=key, sep=sep, i=i)<EOL>while index_key in d:<EOL><INDENT>i += <NUM_LIT:1><EOL><DEDENT>apply_and_resolve_conflicts(d, array[i], index_key)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>d[new_key] = d.pop(key)<EOL><DEDENT><DEDENT>return d<EOL>
In place dict flattening.