from typing import List


def __expand_lists(expression: str) -> List[str]:
    """Expand lists in a given expression.

    Args:
        expression: The expression to expand.

    Returns:
        The lists expanded from the expression.
    """

    # Expand lists.
    results = [expression]
    index = 0
    while index < len(results):
        res = results[index]

        # Find first opening bracket. If there isn't one then we're done.
        open_idx = res.find("{")
        if open_idx == -1:
            index += 1
            continue

        # Find matching closing bracket and extract components. If there's no
        # matching bracket, we're done.
        close_idx = open_idx + 1
        component_idx = close_idx
        level = 0
        components: List[str] = []
        while close_idx != len(res) and not (
            res[close_idx] == "}" and level == 0
        ):
            if res[close_idx] == "{":
                level += 1
            elif res[close_idx] == "}":
                level -= 1
            elif res[close_idx] == "," and level == 0:
                components.append(res[component_idx:close_idx])
                component_idx = close_idx + 1

            close_idx += 1

        if close_idx == len(res):
            index += 1
            continue

        # Add the last component.
        components.append(res[component_idx:close_idx])

        # Add the expanded strings to the results collection, replacing the
        # item that we used to generate them.
        prefix, suffix = res[:open_idx], res[close_idx + 1 :]
        results.pop(index)
        results += [prefix + c + suffix for c in components]

    return results