code: def counter_mean_and_median(counter):
      
      if not counter:
          return np.nan, np.nan
  
      total = sum(v for k, v in counter.items())
      mid = total / 2
      weighted_sum = 0
      items_seen = 0
      median_found = False
      for k, v in sorted(counter.items()):
          weighted_sum += k * v
          items_seen += v
          if not median_found and items_seen >= mid:
              median = k
              median_found = True
      mean = weighted_sum * 1. / total
      return mean, median
docs: Calculate the mean and median value of a counter