[open] Splitting list/file into smaller chunks
Hi all,
I would appreciate some help with splitting a file into smaller parts. I´m still not that familiar with OpenSesame, so maybe this issue is rather simple to most of you...
I´ve got an item pool of overall 390 items and need to
shuffle the list (got that already)
split this item pool into two halves ("block1" and "block2", 195 each)
and then create various sublists for each half:
"study_list" items for each block, 100 items each (I need a "study_list_block1" and "study_list_block2", each containing the first 100 items of block1 or block2, respectively
distractor/lure items for each block, 50 items each (I need a list "distractors_block1" and "distractors_block2", each containing item 101-150 of the lists "block1" or "block2", respectively
buffer items for each block, items 151-170 of "block1" or "block2"
and finally the last 25 items, items 171-195, which need to be converted into anagrams later on
Since I need to call the lists throughout the experiment and the items shouldn´t mix up (e.g. some items shown twice, once in block1, once in block2), the lists should be created only once at the beginning and then stay as they are. So I might save the new lists somewhere in order to be able to call them whenever they´re needed later on. I don´t know if this is the best solution, maybe there´s another, easier approach?
As I said, I´ve already shuffled the main list and then tried to split it into two halves as follows:
def split_list(list_total):
half_list_total = len(list_total)/2
return list_total[:half_list_total], list_total[half_list_total:]
This seems to work for splitting the list into halves but not when I tried to draw specific items from the lists (e.g. studylist_b1 = list_b1_total[0:99].
Apart from that, I wanted to write out the newly created lists by "writelines" but this didn´t work either. Would this be the correct command at all?
I´d be really glad if someone could give me some hints
Thank you so much in advance!
Comments
Hi,
In general, you seem to be almost there. Here, a few remarks:
In this case, it might be a better idea to save the final list as a tuple, in this way you make sure that it isn't changed by accident, while still being able to retrieve values just the way you would have done with lists.
Usually, this isn't necessary, because everything that you define in an
inline_script
will be available in every otherinline_script
in your experiment. Unless, you don't need the list anywhere else, you're fine. However, if you use some values of your lists in asketchpad
for example, you probably need to save it as instance of the experiment first. So simplyexp.my_list = my_list
. In doing so, you will be able to access it later as [my_list][index].I don't see why this shouldn't work. The code seems to be fine. Especially, if you consider, that you're basically repeating the exact same operation every time you create another subset of the list. The only thing that changes is the index.
This depends on the content of your list.
writelines
expects a list of strings. If you're list doesn't hold strings in it, you'll have to use something else (e.g. pickles), or simple convert the lists' values first to strings (recommended).I hope this was of any help for you.
Good luck,
Eduard