def merge_with(func, *dicts, **kwargs):
    if len(dicts) == 1 and not isinstance(dicts[0], dict):
        dicts = dicts[0]
    factory = _get_factory(merge_with, kwargs)

    result = factory()
    for d in dicts:
        for k, v in iteritems(d):
            if k not in result:
                result[k] = [v]
            else:
                result[k].append(v)
    return valmap(func, result, factory)
Merge dictionaries and apply function to combined values
dataset/ETHPy150Open pytoolz/toolz/toolz/dicttoolz.py/merge_with