def merge_data_by_id(data):
    result = {}
    for datum in data:
        id = datum["id"]
        item = result.get(id, {})
        item.update(datum)
        result[id] = item
    return result.values()


def map_data(klass, query, order, data_keys, output_keys):
    result = klass.objects.filter(query).order_by(order)
    data = result.values_list(*data_keys)
    return [dict(zip(output_keys, values))
            for values in data]

def coalesce_dictionaries(data, merge_field="id"):
    "Takes a sequence of dictionaries, merges those that share the
    same merge_field, and returns a list of resulting dictionaries"
    result = {}
    for datum in data:
        merge_id = datum[merge_field]
        item = result.get(merge_id, {})
        item.update(datum)
        result[merge_id] = item
    return result.values()


def map_data(klass, query, order, data_keys, output_keys):
    result = klass.objects.filter(query).order_by(order)
    data = result.values_list(*data_keys)
    return [dict(zip(output_keys, values))
            for values in data]

Rename merge_data_by_id, add doc-string, get rid of id as a local
[AC-4835] Rename merge_data_by_id, add doc-string, get rid of id as a local
