def powerset_tree(lst, initial=True, terminator=''):
    # If it happens to be a list, convert it first.
    if isinstance(lst, str):
        lst = substring_list(lst)
    # Go over each item in the list...
    for k, substr in enumerate(lst):
        # If it's the very first item in the **top outer most list**,
        # just make it a singleton list, since it's the full string
        # and we don't want to subdivide it.
        if initial:
            lst[k] = [substr + terminator]
            # Make sure to set this to false so it **never runs again**.
            initial = False
        else:
            # If the substring is a singleton list, continue,
            # as it's the last item in the substring sublist.
            if len(substr) == 1:
                continue
            # Otherwise, recursively travel down into this list,
            # repeating the process with a string one character
            # smaller than the last -- but nest it inside
            # this list so the parent is referenced as the first key
            # and the children elements are
            # inside the second key, as a list.
            lst[k] = [substr + terminator, powerset_tree(
                substring_list(substr[1:]), initial=initial)]
    # Return the final list.
    return lst
Creates nested powersets of the word list for each key
dataset/ETHPy150Open christabor/MoAL/MOAL/helpers/generic.py/powerset_tree