I guess the easiest way is indeed to use a dictionary which clearly has an ID for each word. You can then get 50 random items from that dict and log their IDs.
from expyriment import control, design, misc, stimuli
# SETTINGS
ITI = 1000 # in milliseconds
words = {1: "hello",
2: "world",
3: "some",
4: "more",
5: "words",
6: "needed"}
# DESIGN
exp = control.initialize()
exp.add_data_variable_names(["Phase", "WordID", "Studied", "Response", "RT"])
study = design.Block(name="Study phase")
for id in design.randomize.rand_int_sequence(1, len(words.keys()))[:len(words) / 2]:
t = design.Trial()
t.set_factor("WordID", id)
study.add_trial(t)
exp.add_block(study)
test = design.Block(name="Test phase")
for id in design.randomize.rand_int_sequence(1, len(words.keys())):
t = design.Trial()
t.set_factor("WordID", id)
test.add_trial(t)
exp.add_block(test)
# RUN
control.start()
for counter, block in enumerate(exp.blocks):
stimuli.TextScreen(block.name, "Press [SPACE] to continue").present() exp.keyboard.wait(misc.constants.K_SPACE)
for trial in block.trials:
word_id = trial.get_factor("WordID")
stim = stimuli.TextLine(words[word_id])
exp.clock.wait(ITI - stim.preload())
stim.present()
key, rt = exp.keyboard.wait()
stim.unload()
word_id in exp.blocks[0].get_trial_factor_values("WordID"),
key, rt])
control.end()
I hope this helps.