In place dict flattening.

def flatten_dict(d, prefix='', sep='.'):
    """In place dict flattening.
    """
    def apply_and_resolve_conflicts(dest, item, prefix):
        for k, v in flatten_dict(item, prefix=prefix, sep=sep).items():
            new_key = k
            i = 2
            while new_key in d:
                new_key = '{key}{sep}{index}'.format(key=k, sep=sep, index=i)
                i += 1
            dest[new_key] = v

    for key in list(d.keys()):
        if any(unicode(prefix)):
            new_key = u'{p}{sep}{key}'.format(p=prefix, key=key, sep=sep)
        else:
            new_key = key
        if isinstance(d[key], (dict, collections.Mapping)):
            apply_and_resolve_conflicts(d, d.pop(key), new_key)
        elif isinstance(d[key], six.string_types):
            d[new_key] = d.pop(key)
        elif isinstance(d[key], (list, collections.Mapping)):
            array = d.pop(key)
            for i in range(len(array)):
                index_key = '{key}{sep}{i}'.format(key=key, sep=sep, i=i)
                while index_key in d:
                    i += 1
                apply_and_resolve_conflicts(d, array[i], index_key)
        else:
            d[new_key] = d.pop(key)
    return d