docs: def _group_groups(perm_list):
      """Group permissions by group.
  
      Input is list of tuples of length 3, where each tuple is in
      following format::
  
          (<group_id>, <group_name>, <single_permission>)
  
      Permissions are regrouped and returned in such way that there is
      only one tuple for each group::
  
          (<group_id>, <group_name>, [<first_permission>, <second_permission>,...])
  
      :param list perm_list: list of touples of length 3
      :return: list tuples with grouped permissions
      :rtype: list
  
      """
      perm_list = sorted(perm_list, key=lambda tup: tup[0])
  
      grouped_perms = []
      for key, group in groupby(perm_list, lambda tup: (tup[0], tup[1])):
          grouped_perms.append((key[0], key[1], [g[2] for g in group]))
  
      return grouped_perms