Generating Code to Shuffle Outcomes Lists

PsychoPy version 2026.1.3

Hi there! I am building a modified Iowa Gambling Task and am trying to write a code to shuffle between 4 premade lists of outcomes, so every participant gets a different set of outcomes every experiment. I have the 4 lists made, each with a “good” and “bad” outcome list, and want the task to shuffle between these 4 lists each time it’s run. I am also wondering if the code should be in the Before Experiment tab?

Here’s an image of my outcomes lists so far:

Thanks!

Hello @Charlotte_Gagnon

Your approach won’t work. You define G_DrawOrder and B_DrawOrdner four times with different values. But this results in overwriting the previous definition such that only the last will be valid.

There are different ways to achieve your objective. One solution is as follows.

Create a condition file with the columns condition. In this columns enter whether it is a G_DrawOrder or a B_DrawOrder trial. In a column named outcome enter your values of G_DrawOrder and B_DrawOrder. Insert the values of your four lists row-wise. In a Begin Experiment tab use the following.

part_id = int(expInfo['participant'])

block_index = (part_id - 1) % 4

all_blocks = ["0:50", "50:100", "100:150", "150:200"]
use_rows = all_blocks[block_index]

thisExp.addData('chosen_block_range', use_rows)

In your trial loop enter $use_rows in Selected rows. This code assume that you 50 trials per list. You will certainly need to adapt this to your needs. Participant 1 → list 1, participant 2 → list 2, participant 3 → list 3, participant 4 → list 4.

In fact, I assume that you will present the G_DrawOrder and B_DrawOrder trials consecutively.

Another approach closer to your current set up is as follows:

set_A = {
    'G_DrawOrder': [100, 100, 100, 50],
    'B_DrawOrder': [-250, -100, 0, -50]
}

set_B = {
    'G_DrawOrder': [100, 150, 100, 100],
    'B_DrawOrder': [-1250, 0, 0, 0]
}

set_C = {
    'G_DrawOrder': [50, 50, 50, 50],
    'B_DrawOrder': [-50, -25, -75, 0]
}

set_D = {
    'G_DrawOrder': [50, 50, 50, 50],
    'B_DrawOrder': [0, 0, 0, -250]
}

all_sets = [set_A, set_B, set_C, set_D]

random.shuffle(all_sets)

deck = all_sets[0]

Access a value of your deck the latter in trial

current_gain = deck['good'].pop(0)
current_loss = deck['bad'].pop(0)

This approach does not include list selection based on the participant number. However, this could easily be included. I think the former approach might be advantageous, as it includes the condition in the results file, which simplifies the analysis. Also, you could use the same trial-routine for G_DrawOrder and B_DrawOrder, which will also simplify analysis.

Best wishes Jens