vendredi 1 février 2019

How to create a new list that is combination of 2 different lists elements without repetition?

I am trying to create a canvas that has 2 stimulis. Please note that stimuli lists can be longer.

sti1 = ["death", "pain"]
sti2 = ["glass", "book"]

These stimulis will shown like this:

frame 1: death - book / frame 2: glass - pain

But they must shuffle correctly. I mean if there is a "death x book" combination, there must not be another one. Also, all combinations must be shown. Also, all frames must contain one word from sti1 and one word from sti2.

Here is what I thought:

  1. create a combination list that contains all the combinations.

  2. use for loop to itarate.

If there is another solution than creating a combination list and iterate it, I am open to new things.

I tried: random.choice itertools.permutations itertools.combinations (most close answer but this just can combine 1 list like sti1)

Expected result: combination_list = [(death, glass), (death, book), (pain, glass), (pain, book)]




Aucun commentaire:

Enregistrer un commentaire