I want to find for each list within a list of lists what intersections occur when taking set intersection for each list in another list of lists.
Hopefully that makes sense.
I have tried
Outer[Intersection[#1, #2] &, p1, p2]
MapThread[Intersection, {p1, p2}] (* This works but only when p1 and p2 are same length *)
where p1 = {{1, 2, 6}, {1, 2, 4, 6}, {1, 2, 3, 5, 6}}
and p2= {{3, 5, 6}}
But no such luck.
The output should show that 6
is the only number in common between the list in p2 and each list in p1. If p2 contains another list, then the comparision function should perform the same check as with the 1st list in p2 but only care about the intersections that happen between this 2nd list and all the lists in p1.
I also should mention that when no intersections occur between list i in p1 with list j in p2 then something need to denote this (like {}
)
Ideally I want and output like
result = {{{6},{6},{6}},{*results for 2nd element in p2*}}
etc.
{3,5,6}
? $\endgroup$