# Using code to randomize word stimulus-how to make subgroups

Hello everyone,

This is a memory study which involves 64 study/old words and 128 test words (64 old + 64 new). Words at study will be presented in 4 different colors (red, yellow, blue, green) and with a point-value number (1 or 10). Here is the code that can achieve randomization of the words.

``````#access the xls the stimulus file
inbook = xlrd.open_workbook(infile)
insheet = inbook.sheet_by_index(0)

#arrays for our stimuli
word = []

#read the stimuli from our sheet
for rowx in range(1,num_items+1):
row = insheet.row_values(rowx)

#saving the word to the word array
word.append(row[0])

#randomize the order of the word array
random.shuffle(word)

#arrays for our final stimuli
word_item     =[]
old_new       =[]
word_color    =[]
point_value   =[]

#creat in final stimulus list
for i in range(num_test):
#assign a word item from the word list
word_item.append(word[i])

#determin the old/new status of items
if i < 64:
old_new.append("old")
else:
old_new.append("new")

#determine the color of the items
if i < 16:
word_color.append("red")
elif i < 32:
word_color.append("yellow")
elif i < 48:
word_color.append("blue")
elif i < 64:
word_color.append("lime")
else:
word_color.append("")

#determine the point of the items
if i % 2 != 1:
point_value.append("10")
else:
point_value.append("1")
``````

Now, I want to separate these 64 study words into 4 different blocks (ABAB, Block AB will be in different routines) and also keep that in each block 4 different colors and 2 point numbers are equally distributed among words. I was thinking to separate the word_item array into 4 arrays but don’t know how to achieve that. Below the code above I tried this:

``````word_item1=word_item[0:3,16:19,32:35,48:51]
word_item2=word_item[4:7,20:23,36:39,52:55]
word_item3=word_item[8:11,24:27,40:43,56:59]
word_item4=word_item[12:15,28:31,44:47,60:63]
``````

But got this error
“list indices must be integers, not tuple”. Any help would be greatly appreciated.

It is a bit verbose, but I think you need to take each slice individually:

``word_item1 = word_item[0:3] + word_item[16:19] + word_item[32:35] + word_item[48:51]``

Thank you @Michael, problem solved!