Conditioning foreground images to show only when specific backgrounds have loaded

Hello, I am building an experiment where I need specific color shapes displayed on specific backgrounds as an adaptive staircase design (I haven’t gotten to building the adaptive part yet).

So far, i’ve found success with the help of the following video.

Essentially I have randomized the background images, but I want to “assign” specific foreground images to each background.

Here is the custom code I have so far:

random.seed()

cur_background = 0

background_stim = []
pos1_stim = []
pos2_stim = []
pos3_stim = []
pos4_stim = []
#pos=position, each 'background' has four images in specific positions

infile = 'stims/backgroundstimulus.xlsx'
inbook = xlrd.open_workbook(infile)
insheet = inbook.sheet_by_index(0)

for rowx in range(1,num_items_background+1):
    row = insheet.row_values(rowx) 
    background_stim.append(row[0])
    pos1_stim.append(row[1])
    pos2_stim.append(row[2])
    pos3_stim.append(row[3])
    pos4_stim.append(row[4])

background_order = []

for i in range (num_items_background):
    background_order.append(i)

random.shuffle(background_order)

Don’t mind that there are four sets of “pos” lists, as it will be the same for all.

My question is, after randomizing the background_order, how do I tell python to load a specific foreground shape based on the one that gets displayed? I’m not well-versed in code but in my mind it would be something like:

if i = 0
   pos1_stim('specific image file name')