def merge_dict(d1, d2, merge=(lambda x, y: y)):
 if (not isinstance(d1, dict)):
  return merge(d1, d2)
 result = dict(d1)
 if (d2 is None):
  return result
 for (k, v) in list(d2.items()):
  if (k in result):
   result[k] = merge_dict(result[k], v, merge=merge)
  else:
   result[k] = v
 return result

def merge_dict ( d1 , d2 , merge = ( lambda x , y : y ) ) : if ( not isinstance ( d1 , dict ) ) : return merge ( d1 , d2 ) result = dict ( d1 ) if ( d2 is None ) : return result for ( k , v ) in list ( d2 . items ( ) ) : if ( k in result ) : result [ k ] = merge_dict ( result [ k ] , v , merge = merge ) else : result [ k ] = v return result
merges two dictionaries .