def _GetTopN(objects, n):
  """Returns top n objects with maximum count.

  Args:
    objects: any object that has count property
    n: number of top elements to return
  Returns:
    top N elements if objects size is greater than N otherwise the map elements
    in a sorted order.
  """
  return sorted(objects, key=lambda o: o.count, reverse=True)[:n]