Code:
class CombinatoricalUtils:
# combo related algorithmic tools
def __init__(self):
self.result: list[str] = []
def _generatePermutations(self, lists: list[list[str]], result: list[str], depth: int, current: str):
# this function has a private modifier (the "_" makes it so)
if depth == len(lists):
result.append(current)
return
for i in range(0, len(lists) + 1):
self._generatePermutations(lists, result, depth + 1, current + lists[depth][i])
def generatePermutations(self, lists: list[list[str]]):
# generate all permutations between all string lists in lists, which is a list of lists of strings
self.result = []
self._generatePermutations(lists, self.result, 0, "")
def generatePermutations(self, *lists: list[list[str]]):
# this is the varargs vertion of this function
# example method call: cu.generatePermutations(l1,l2)
temp_lists:list[list[str]] = []
for i in range(0, len(lists)):
temp_lists.append(lists[i])
self.result = []
self._generatePermutations(temp_lists, self.result, 0, "")