Random lists creation based on a given variable


there is a precise list of things I’m trying to do but can’t really figure out how:

This is how my variables table looks like. There are 40 rows in total, each corresponding to a different verb and a different object. Verb_type only has two modalities, and should ideally be usefull to help me make two lists.

Those lists will be used in two different loops. Each list shoud contains 20 items, an item beeing defined as a combination of a verb and an object (e.g. to watch a pencil; to grasp a saw…).

First problem (not the main one): as i don’t want to display always the same verb with a given object, a first issue is to shuffle verb and object independantly from each other, at the begining of the experiment.

Second problem, as I said above, lists should be builded according to the verb_type variable. Each list should contain 20 items, 10 belonging to the “action” verb type, and 10 belonging to the “attention” verb type. Finally, I dont want any verb or object to be repeated, neither within or between lists. If the verb to walk is in an item of the first list it should not be in the second, if the object pencil is in list 1 it shouldn’t be in list 2… etc
In other words, the 40 verbs and 40 objects would always be seen, by every participant. But they should not always be displayed with the same object/verb, and not always in the same list (loop).

I know almost nothing about coding. The only thing i managed to do is to make two random list with the following code, but it’s far to be enough as it doesn’t shuffle anything and doesn’t take verb_type into account.

import random

vector = list(range(40))

RowsLoop1 = random.sample(vector, 20)
remaining_vector = list(set(vector) - set(RowsLoop1))

RowsLoop2 = random.sample(remaining_vector, 20)

So, here I am. Any suggestion would be much appreciated if some of you have already dealt with comparable issues. Thank you for reading!


Please have a look at my independent randomisation online demo.