def _dicts_to_list(list_of_dicts, keys):
  """Transforms a list of dicts to a list of values.

  This is useful to create a list of Tensors to pass as an argument of
  `host_call_fn` and `metrics_fn`, because they take either a list as positional
  arguments or a dict as keyword arguments.

  Args:
    list_of_dicts: (list) a list of dicts. The keys of each dict must include
      all the elements in `keys`.
    keys: (list) a list of keys.

  Returns:
    (list) a list of values ordered by corresponding keys.
  """
  list_of_values = []
  for key in keys:
    list_of_values.extend([d[key] for d in list_of_dicts])
  return list_of_values