# Pop empty list error + pop function online

Hello everyone,

I encountered a problem very common to the forum and tried to solve it but failed till now. Here below is my experimental design. I have two condition of image presentation (random and sequential). In total I have 4 big blocks and each block has 20 mini blocks of 5 item sequences. So I have an external loop to choose among the random sequence (160 repetitions of the mini blocks and it could a random or a sequential one coded 1,0. In the inside loops I have a list of images in the begin experiment for each condition inserted likewise:

Begin Experiment

``````Faces= [f'Face_{i}.png' for i in range(1,21)] * 4;
Scenes= [f'Scene_{i}.png' for i in range(1,21)] * 4;
Bodies= [f'Body_{i}.png' for i in range(1,21)] * 4;
Tools=  [f'tool_{i}.png' for i in range(1,21)] * 4;
Scrambled= [f'scrambled_{i}.tif' for i in range(1,21)] * 4 ;

``````

Begin routine

``````if Order == 'F':
image_file = Faces.pop()
elif Order == 'S':
image_file = Scenes.pop()
elif Order == 'B':
image_file = Bodies.pop()
elif Order == 'Sr':
image_file = Scrambled.pop()
elif Order == 'T':
image_file = Tools.pop()

``````

In essence there are 20 images of each category but repeated 4 times for both conditions. So from the 160 conditions in the random part 68 are random and 12 sequence while in the sequence 68 are sequence and 12 random. So I created my list of random images by multiplying by 4 : 20x4x5 = 400 images that are enough for the 80 iterations of each condition. Now when I run it it stops at 70 trials, 14 iterations and gives the error: pop from empty list. I tried making the list bigger by multiplying by 5 or 8 but i get the same error. I checked all the images and are correct. I guess there is a problem in how many trials and images I have but I cannot figure out my way out of this. Any ideas or suggestions? Thanks in advance for any help.

PS. I have another small question that is relevant so let me leave it here as well. The pop function does not work online so I saw on the creeb shit I should use shift(). But shift gives me an error: shift is not a function. If anyone has a clue also about this I would be grateful.

My kindest regards to everyone,
Anastasia

I would suggest putting in some debugging code (e.g. in the â€śbegin routineâ€ť tab of a code component on your trial routine) so you can monitor how the lengths of the lists change as the experiment proceeds (itâ€™s best to temporarily make your experiment show in a small window rather than be full-screen, so you can see the print statement output in real time). e.g.

``````print(f'Faces: {len(Faces)}. Scenes: {len(Scenes)}') # etc
``````
1 Like

thanks for the great tip! I tried it out and it seems that at the begin experiment it loads correctly the list of 20 images x 4 times so total 80 for each category but then in each routine it seems that the list is only 20 going down. So i guess it takes the original list not the extended one. Any idea how can I deal with that?

Begin experiment :

``````Faces: 80. Scenes: 80.Bodies:80. Tools: 80. Scrambled: 80
``````

Begin routine:

``````Faces: 20. Scenes: 19.Bodies:20. Tools: 20. Scrambled: 20
Faces: 20. Scenes: 19.Bodies:20. Tools: 19. Scrambled: 20
Faces: 20. Scenes: 19.Bodies:20. Tools: 19. Scrambled: 19
Faces: 20. Scenes: 19.Bodies:19. Tools: 19. Scrambled: 19
Faces: 19. Scenes: 19.Bodies:19. Tools: 19. Scrambled: 19
Faces: 19. Scenes: 19.Bodies:18. Tools: 19. Scrambled: 19
Faces: 19. Scenes: 18.Bodies:18. Tools: 19. Scrambled: 19
Faces: 19. Scenes: 18.Bodies:18. Tools: 18. Scrambled: 19
Faces: 19. Scenes: 18.Bodies:18. Tools: 18. Scrambled: 18
``````

You havenâ€™t shown us the code that distinguishes between an â€śoriginalâ€ť and and â€śextendedâ€ť list. All we can see is code that generates five lists, each of length 80.

Somewhere between that code at the beginning of the experiment, and the code you show us at the beginning of the routine, something happens to either shrink those lists or replace them with ones of length 20. So look through any other code components to see if anything is interfering with your original lists of length 80.

It can sometimes be easier to just compile the experiment to a Python script and then search through that file for things like `Faces =` to see if you have any other code floating around that might over-write the original list.

1 Like

Shame to admit but I had a naive error that meshed up the sequenses. I had list with same name e.g. face twice so it would overwrite the length of the first lists. I managed to understand it it with the great tips. Thanks again.