Howdy, Stranger!

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

Supported by

[solved] What's wrong with my .pop()?

edited April 2015 in OpenSesame

I'm making a block design (4 blocks, 50 trials each) and I've started writing an inline script to pull 5 letters pseudo-randomly from the whole alphabet (list 'alpha') and append them to individual lists for each block.

I've used 'pop()' so that letters from alpha are not returned to the list as I don't want repetitions of letters at all.
My problem is that when I run 'build(letter1)' (or any other of the four new lists) I get an error telling me "...pop from empty list" - presumably meaning that it thinks that list 'alpha' is empty.

Any idea what rookie mistake(s) I've made?

from random import shuffle
###############################################
# Need to make different stimuli for each block:
alpha = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N',\
'O','P','Q','R','S','T','U','V','W','X','Y','Z']
shuffle(alpha)
# Create letter groups for each block:
letter1 = []
letter2 = []
letter3 = []
letter4 = []

def build(n):
    count = 0
    while count != 5:
        n.append(alpha.pop())
        count =+ 1
    else:
        print(n)

Comments

  • edited 7:03AM

    Hi,

    I think the reason why it isn't working is that you wrote count =+1 and not count += 1. Therefore, the while loop is running forever and popping all the letters from alpha, until it's empty.

    Can you check whether this solves the issue?

    Eduard

    Buy Me A Coffee

Sign In or Register to comment.