Reputation: 31
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:
create a combination list that contains all the combinations.
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)]
Upvotes: 0
Views: 50
Reputation: 88285
For that you want itertools.product
:
from itertools import product
list(product(sti1,sti2))
[('death', 'glass'), ('death', 'book'), ('pain', 'glass'), ('pain', 'book')]
Upvotes: 2