code: def mann_whitney_u(sample1, sample2, use_continuity=True):
      
      # Merge dictionaries, adding values if keys match.
      sample = sample1.copy()
      for k, v in sample2.items():
          sample[k] = sample.get(k, 0) + v
  
      # Create a ranking dictionary using same keys for lookups.
      ranks = _rank(sample)
  
      sum_of_ranks = sum([sample1[k] * ranks[k] for k, v in sample1.items()])
      n1 = sum(sample1.values())
      n2 = sum(sample2.values())
  
      # Calculate Mann-Whitney U for both samples.
      u1 = sum_of_ranks - (n1 * (n1 + 1)) / 2
      u2 = n1 * n2 - u1
  
      tie_correction = _tie_correct(sample)
      if tie_correction == 0:
          raise ValueError('All provided sample values are identical.')
  
      sd_u = math.sqrt(tie_correction * n1 * n2 * (n1 + n2 + 1) / 12.0)
      mean_rank = n1 * n2 / 2.0 + 0.5 * use_continuity
      z = abs((max(u1, u2) - mean_rank) / sd_u)
  
      return mwu_result(min(u1, u2), ndtr(-z))
docs: Computes the Mann-Whitney rank test on both samples.
  
      Each sample is expected to be of the form::
  
          {1: 5, 2: 20, 3: 12, ...}
  
      Returns a named tuple with:
          ``u`` equal to min(U for sample1, U for sample2), and
          ``p`` equal to the p-value.