def merge_hash(a, b):
 _validate_mutable_mappings(a, b)
 if ((a == {}) or (a == b)):
  return b.copy()
 result = a.copy()
 for (k, v) in iteritems(b):
  if ((k in result) and isinstance(result[k], MutableMapping) and isinstance(v, MutableMapping)):
   result[k] = merge_hash(result[k], v)
  else:
   result[k] = v
 return result

def merge_hash ( a , b ) : _validate_mutable_mappings ( a , b ) if ( ( a == { } ) or ( a == b ) ) : return b . copy ( ) result = a . copy ( ) for ( k , v ) in iteritems ( b ) : if ( ( k in result ) and isinstance ( result [ k ] , MutableMapping ) and isinstance ( v , MutableMapping ) ) : result [ k ] = merge_hash ( result [ k ] , v ) else : result [ k ] = v return result
recursively merges hash b into a so that keys from b take precedence over keys from a .