code: def make_combs(
      entity_ids: List[List[str]], permut: bool
  ) -> List[List[str]]:
      entity_ids = [
          [(entity, n) for n, entity in enumerate(entities_list)]
          for entities_list in entity_ids
      ]
      entity_ids = list(itertools.product(*entity_ids))
      entity_ids = [
          comb
          for comb in entity_ids
          if not (
              all(
                  [
                      comb[i][0][0].split("/")[-1]
                      == comb[0][0][0].split("/")[-1]
                      for i in range(len(comb))
                  ]
              )
              and not all(
                  [
                      comb[i][0][0] == comb[0][0][0]
                      for i in range(len(comb))
                  ]
              )
          )
      ]
      entity_ids_permut = []
      if permut:
          for comb in entity_ids:
              entity_ids_permut += itertools.permutations(comb)
      else:
          entity_ids_permut = entity_ids
      entity_ids = sorted(
          entity_ids_permut, key=lambda x: sum([elem[1] for elem in x])
      )
      ent_combs = [
          [elem[0] for elem in comb] + [sum([elem[1] for elem in comb])]
          for comb in entity_ids
      ]
      return ent_combs
  
file_path: DeepPavlov/deeppavlov/models/kbqa/utils.py
imports: import itertools
  import re
  from collections import namedtuple
  from typing import List, Tuple, Dict, Any
label_desc: Use image node_id 5 for calling a global function with example usage: make_combs(entity_ids, permut) and returns: ent_combs