# Unknown Issue in Code Resulting in List Drawing Twice

I am currently having an issue figuring out where to fix my code for my custom loop. Here is a picture of my set up:

I have 8 sets of word lists that only have 4 trials. After the four trials finish, the participant should enter into either a “blank” screen or complete a round of random math equations. After the blank screen or math equations, they complete a recall task that should keep track of what they previously saw. I currently have custom code that is set up to call a datafile and read in the stimuli and reiterate through that. I’m not really sure where I’m having an issue.

This is the code on my Begin Experiment routine:

``````from random import shuffle
import random
import pandas

list_0 = ['A','B']
list_25 = ['I','J']
list_50 = ['Q','R']
list_75 = ['Y','Z']

shuffle(list_0)
shuffle(list_25)
shuffle(list_50)
shuffle(list_75)

# Pair each element from list_0 and list_25 with the corresponding task

# Combine the two lists
all_pairsList = pairsList_0 + pairsList_25 + pairsList_50 + pairsList_75

shuffle(all_pairsList)

trial_list = all_pairsList

##################################################
loop_counter = 0

# Get the current trial dictionary
current_trial = trial_list[loop_counter]

# Set the conditions file based on 'item'
item_file = f"{current_trial['item']}.xlsx"
retrieval_file = f"{current_trial['item']}_Retrieval.xlsx"

# Save information to be used in the next routine
``````

In theory, this should be controlling the conditions that are shown so that the lists receive one math and one blank condition. NOTE: The last part of the code I have tried to get rid of multiple times, but then it errors out on me and says variables don’t exist. If I initialize the variables, they never get filled.

Here is the code on my WM_WP_L1 variable:

``````loop_counter = phase2.thisN

# Get the current trial dictionary
current_trial = trial_list[loop_counter]

# Set the conditions file based on 'item'
item_file = f"{current_trial['item']}.xlsx"

# Save information to be used in the next routine

print(trial_list[loop_counter])
``````

Again, in theory, this is suppose to only set the list to the current loop counter. This is what iterates to the new list after 4 trials. The loop counter appears to work correctly and gives output that looks like this:

Now, the issue is, despite the correct item and task and loop_counter, it draws the first list of words twice. So, it gives me 8 total lists, with the first list being repeated twice.

I have no clue where the code is going wrong. Any insight?

Update: I believe the issue is in the Begin Experiment routine where initialize everything, but merely initializing the variables leads to the variables not being recognized, even when I globalize them.

I’m still having issues, so if anyone has any guess, I’ll take them. I have tried the following to no avail:

1. Globalizing all variables and setting them to 0
2. Setting the first list to a pseudo-list that wouldn’t count towards scoring but was still shown
3. Creating an “if” loop to force the second trial to be a specific list
4. Creating a loop counter that only changed the list name after 4 counts of WM_Trials

None of these options worked. The program still shows whatever the first list is twice and calls it another list name. So, the computer believes it is displaying 8 unique lists.

This issue has been resolved.