Seperating a list by unique items [SOLVED]
Posted: Thu Jan 15, 2015 3:14 pm
I'm trying to do something I'm sure is simple, but I can't find how to do it. I'm probably missing something!
I have a list in a variable, lets call it "StimList". The list has 80 lines, and each line has 3 items, all 3 items are words. For example lines 1-4 might look like:
file.bmp, file2.bmp, distinct
file3.bmp, file4.bmp, distinct
file5.bmp, file6.bmp, typical
file7.bmp, file8.bmp, typical
I'm trying to write some code that looks at each line, and puts that line into a new list based on the content of the third item (i.e. in this case distinct/typical). So the result would be two lists, one with all the distinct lines in and one list with all the typical lines in. However, I want to do use code that does this for all unique words as the third item, not just distinct and typical. So, for example, if the third line could contained one of three words, e.g. bird, cat, dog rather than two words e.g. distinct, typical. In case that's unclear, if I know in advance what the words in the third item were, I could use code that looks like something like this:
But this would only work for the specific words distinct and typical as the third item. If I tried to use that on a list with different words, it wouldn't work. I think I need a way to put all unique values of the third item into its own list, then I can use that list to match to the items in StimList. How do I do this?
Thanks in advance!
Symiant
I have a list in a variable, lets call it "StimList". The list has 80 lines, and each line has 3 items, all 3 items are words. For example lines 1-4 might look like:
file.bmp, file2.bmp, distinct
file3.bmp, file4.bmp, distinct
file5.bmp, file6.bmp, typical
file7.bmp, file8.bmp, typical
I'm trying to write some code that looks at each line, and puts that line into a new list based on the content of the third item (i.e. in this case distinct/typical). So the result would be two lists, one with all the distinct lines in and one list with all the typical lines in. However, I want to do use code that does this for all unique words as the third item, not just distinct and typical. So, for example, if the third line could contained one of three words, e.g. bird, cat, dog rather than two words e.g. distinct, typical. In case that's unclear, if I know in advance what the words in the third item were, I could use code that looks like something like this:
Code: Select all
repeat for each line thisline in StimList
if item 3 of thisline is distinct then put thisline after variable1
if item 3 of thisline is typical then put thisline after variable2
end repeat
Thanks in advance!
Symiant