from functools import reduce


def merge_with(fn, *dicts):
    """Merge 2 or more dicts, using `fn` for conflicting values"""

    def _merge(d1, d2):
        for k, v in d2.iteritems():
            if k in d1:
                d1[k] = fn(d1[k], v)
            else:
                d1[k] = v
        return d1
    return reduce(_merge, dicts, {})