I have a list of pairs of values. Some of those pairs are invalid based on another list. I would like to select only the valid pairs.
list1 = {"abc", "def", "ghi", "jkl", "mno"};
list2 = {{"abc", 1}, {"def", 2}, {"ghi", 3}, {"jkl", 4}, {"mno", 5}};
sel = {{2}, {}, {4}, {1}, {7}};
Pick[list1, sel, {_}]
Pick[list2, sel, {_}]
list1 is a sample of what I would like. list2 is similar to my actual case. sel is the result of Position
where I'm checking a corresponding list against valid cases. When the result of Position
is an empty list, I do not want the values in list1 or list2.
The output from the above code is:
I see from the documentation that what I'm doing with list2 is not valid. My question is what is a good way to do this? I want my original list2, but without {"def",2}. Everything I can think of is pretty messy.