Randomising pairs of stimuli, but then reusing these random pairs in subsequent trials based on type?

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): MacOS Monterey 12.5.1
PsychoPy version (e.g. 1.84.x): v2022.2.4
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:
I am working on an experiment for my Master’s thesis and I have very very limited PsychoPy experience. I am mostly working with the builder but I have been using code for randomisation and image presentation and such.

I have two lists of image stimuli in an excel spreadsheet, list A and list B. These images have been paired up, so A has been randomly paired with B. List B has been randomly paired with a word stimulus as well, which falls under one of three categories. I am now creating a test phase where I want to compare preferences for within-list images based on the word category image B was paired with.

For example, the test phases would present B-category1 with B-category2, B-category1 with B-category3, B-category2 with B-category3, and the same for list A. I am assuming this will be possible, since I am logging all of these variables by using thisExp.addData, but I don’t know how to ‘reach into’ this data to get this, with the randomised order being specific for each participant (and ideally I would like the test phase to be randomised differently from the association phases)

What did you try to make it work?:
I do not know where to start, since each participant will have a randomised presentation. The image stimuli themselves are not important, but rather the association between List A and B and then the word stimuli and word stimulus category.

I think maybe using an if/elif/else statement might work, e.g. by saying if category = “category1”, display(something), but I’m not sure how to write it when it comes to images and if this will use the logged information