def merge_with(f, *dicts):
    """Returns a dict that consists of the rest of the dicts merged with
    the first.  If a key occurs in more than one map, the value from the
    latter (left-to-right) will be the combined with the value in the former
    by calling f(former_val, latter_val).  Calling with no dicts returns {}."""
    d = dict()
    for _dict in dicts:
        for k in _dict:
            if k in d:
                d[k] = f(d[k], _dict[k])
            else:
                d[k] = _dict[k]
    return d