def _ToList(grouped_occurrences_dict):
  """Converts grouped_occurrences from a dict to a list, and sort the groups by
    the most recent occurrence time, in descending order.

  dom_repeat only accepts array but not json, so converts the
  grouped_occurrences_dict to a list.

  Args:
    grouped_occurrences_dict(dict): A dict of grouped occurrence dicts. Like
      {
          'group1': [
              occurrence1_dict,
              occurrence2_dict
          ],
          'group2': [
              occurrence3_dict,
              occurrence4_dict
          ]
      }

  Returns:
    (list): A list of grouped occurrence dicts. Like
    [
        {
            'group_by_field': 'group1',
            'occurrences': [
                occurrence1_dict,
                occurrence2_dict
            ]
        },
        {
            'group_by_field': 'group2',
            'occurrences': [
                occurrence3_dict,
                occurrence4_dict
            ]
        }
    ]
  """
  grouped_occurrences_by_most_recent_occurrence = [{
      'group_by_field': group_by_field,
      'occurrences': occurrences
  } for group_by_field, occurrences in grouped_occurrences_dict.iteritems()]

  grouped_occurrences_by_most_recent_occurrence.sort(
      key=lambda e: e['occurrences'][0]['time_happened'], reverse=True)

  return grouped_occurrences_by_most_recent_occurrence