code: def weighted_median(y, w):
      
      items = sorted(zip(y, w))
      midpoint = sum(w) / 2
  
      yvals = []
      wsum = 0
  
      for yy, ww in items:
          wsum += ww
          if wsum > midpoint:
              yvals.append(yy)
              break
          elif wsum == midpoint:
              yvals.append(yy)
      else:
          yvals = y
  
      return sum(yvals) / len(yvals)
docs: Compute weighted median of `y` with weights `w`.