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)

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 a key may occur in more than one dict .