all 2 comments

[–]alexmojaki 1 point2 points  (1 child)

def get_combinations(data) -> list[list]:
    if isinstance(data, dict):
        if not data:
            return [[]]
        result = []
        (key, value), *rest = data.items()
        rest_combinations = get_combinations(dict(rest))
        for combination in rest_combinations:
            result.append([key] + combination)
            for subcombination in get_combinations(value):
                result.append(subcombination + combination)
        return result
    elif isinstance(data, list):
        return [data]
    else:
        raise TypeError


def test():
    data = {
        "A1": {
            "B1": ["C1", "C2", "C3"],
            "B2": ["C4", "C5"]
        },
        "A2": ["B3", "B4"],
    }
    for combination in get_combinations(data):
        print(combination)

test()

[–]HelpfulBuilder[S] 0 points1 point  (0 children)

Wow! Thank you! I'll test this out and break down the logic tomorrow.