[solved] What's wrong with my .pop()?
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
Hi,
I think the reason why it isn't working is that you wrote
count =+1and notcount += 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