Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Create Two Identical Lists

Hi everyone,
I'm trying to implement an easy recognition memory experiment with a learning phase and a recalling phase. So I need 2 lists of stimuli that are identical. They should contain the name of the stimulus (stimName) and the category (reconCateg).
To do this I implemented an in_line script at the beginning that creates a list (reconCateg ), shuffles the category variable and copies the list in two separate lists (reconCategLearningGlobal, reconCategReconGlobal).

from random import shuffle #import shuffle

var.reconCateg = [1, 1, 0, 0] #create category list
var.reconCateg = list(var.reconCateg) #coerce to list

#create stimuli list
var.stimName = ["WM-004", "WM-006", "WM-222", "WM-252"]
#shuffle category list
var.reconCateg = shuffle(var.reconCateg)
#copy category list for learning phase
var.reconCategLearningGlobal = list(var.reconCateg)
#copy category list for recognition phase
var.reconCategReconGlobal = list(var.reconCateg)

Subsequently, only stimuli that are not distractors (value 1 in reconCateg) are displayed in the learning phase while all stimuli of the second list are displayed in the recognition phase.

To import the lists to be used in each phase I used another in_line script (one for each phase)

#import the last item of the list for each iteration
var.reconCategLearning = var.reconCategLearningGlobal.pop()

Now I have this error:
'NoneType' object is not iterable
in the in_line script at the beginning. I think it is due to coercing reconCateg to a list, that I need to do to avoid getting the "has no pop attribute" error in the second in_line.

Have you any idea about how to resolve this issue? Or any suggestion to run an experiment as simple as this?
Thanks a lot!!



  • Hi Marco.

    random.shuffle() doesn't return anything. Instead of doing var.reconCateg = shuffle(var.reconCateg), just do shuffle(var.reconCateg). Does that already solve it?


  • Hi Eduard,
    actually works but now it executes only one iteration of each cycle.
    Do you think it has something to do with .pop()?

    var.reconCategLearning = var.reconCategLearningGlobal.pop()

    Maybe I have to copy the whole list? Isn't the in_line inside a loop executed each time?
    Thanks for your help!


  • How did you set up your loop? Could you quickly upload your experiment? Then I can have a look.


  • Here it is!
    I have only 4 stim right now (just for testing the script).
    In the learning phase, just 2 should be presented, while in the recognition phase all 4 should be shown.
    Thanks a lot!!


  • You have to set the repeat values as well. If they are set to 1, then the sequence will repeat only once, regardless of how long your list is.

    Two more remarks:

    var.reconCateg = [1, 1, 0, 0] #create category list
    var.reconCateg = list(var.reconCateg) #coerce to list # THIS LINE DOESNT DO ANYTHING

    2) Not sure whether it is important but if you shuffle one list, your stimName list won't match the shuffled list anymore. If you want to retain the order, you should nest your lists, e.g. l = [[1ststim,1stimname],[2ndStim, 2ndStimName],etc]

    Good luck


  • So dumb! :D Thanks a loooooot!!

    For the remarks, I don't need to shuffle the stimName because the loops are already randomized and the stimName has the same order for both loops. So the only thing I'm randomizing is the assignment of the stimName to the to-be-learned or the distractor category.


Sign In or Register to comment.