This is a followup question to this one.
Let a
and b
be lists of lists like this:
a= {{"apples", "pears", 1, 17},
{"pineapples", "apples", 5, 7},
{"yes", "building", 4, 7},
{"no","camel","rabbit",0}}
b= {{"man", 1, 2, 17},
{"pineapples", "apples", "cow", "yes"},
{"no","camel","carpet","wibble"},
{"yes", "buildings", 4, 7}}
How can I remove from b
every row that doesn't share both its 1st and its 2nd elements, say, in that order and in those specific slots, with any of the rows in a
?
Once they've been deleted in this example, b
would become
b= { {"pineapples", "apples", "cow", "yes"},
{"no","camel","carpet","wibble"}}
As far as I can tell, ∈ can't be used to define a criterion in Cases
.
Select[b, ! FreeQ[a[[All, 1 ;; 2]], #[[1 ;; 2]]] &]
$\endgroup$