def _flatten_to_key_and_means_accumulator_list(batch_values,
                                               compute_weighted=True):
  """Converts a batch of keys, weights, and counts to a list of KV pairs."""
  if compute_weighted:
    keys, total_weights, positive_label_weights, counts = batch_values
    total_weights = total_weights.tolist()
  else:
    keys, positive_label_weights, counts = batch_values
    total_weights = []

  # TODO(b/36603294): Perhaps obviate the tolist(). It is currently used so
  # that we go to native Python types for more efficient followup
  # processing.
  keys = keys.tolist()
  positive_label_weights = positive_label_weights.tolist()
  counts = counts.tolist()

  return zip(keys, [
      _make_count_and_weights_means_accumulator(*batch) for batch in
      itertools.zip_longest(positive_label_weights, total_weights, counts)
  ])
Converts a batch of keys, weights, and counts to a list of KV pairs.
tensorflow_transform/beam/analyzer_impls.py