Howdy, Stranger!

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

Supported by

Counterbalancing between two lists


I want to present stimuli from two different lists (i. e. list a and list b) as mixed. They will come randomly but i want to add the condition that no more than 3 stimuli come from the same list sequentially. Indeed, participants will be presented 3 stimuli from one list (list a), and the next stimuli will be from other list (list b).

Would you help me to solve this problem, please?


  • Hi,

    import random
    new_list = []
    # for simplicity have the lists with 0s and 1s, you can later replace them with
    # the actual stimuli
    list_a = [0]*5
    list_b = [1]*5
    # while not all stimuli have been used
    while len(new_list) != 10:
        if len(new_list)>3: # only start checking once you have enough stimuli in list
            if sum(new_list[-3:]) == 3:
            elif sum(new_list[-3:]) == 0:
                # if not three in a row, choose a random list and select one from there

    I haven't tested the code, but it should give you ideas, I hope. Let me know if you don't understand anything.


  • Hi Eduard,

    Thank you very much :)

Sign In or Register to comment.