[Python] All possible decision paths / outcomes given multiple choices at each decision

Discussão em 'Python' iniciado por Stack, Fevereiro 2, 2025.

  1. Stack

    Stack Membro Participativo

    Given I am iterating through multiple lists of elements that are zipped together, I need to create all possible outcomes given I can only choose an element from a single list at each iteration.

    Example input 1:

    a = [3,19,13]
    b = [20,18,7]


    Example output 1:

    [[3, 19, 13], [3, 19, 7], [3, 18, 13], [3, 18, 7], [20, 19, 13], [20, 19, 7], [20, 18, 13], [20, 18, 7]]


    Example input 2:

    a = ['A','B']
    b = ['C','D']


    Example output 2:

    [['A', 'B'], ['A', 'D'], ['C', 'B'], ['C', 'D']]


    I'm struggling to find the right mathematical terminology to define exactly what I am asking for. I do not think permutations, combinations, or cartesian product are correct or precise enough.

    Continue reading...

Compartilhe esta Página