I have a list filled with a large number of elements, eg. {1,2,3,4,5,6,7}
I wanna partition the list by a reference list. The reference list shows how those elements need to be grouped. eg. {{1,3},{4,6},{7,2,5},{9,10,11}...}. The reference list also contains the unwanted element/sublist.
My current methods are:
list1 = {1, 2, 3, 4, 5, 6, 7};
reflist = {{1, 3}, {4, 6}, {7, 2, 5}, {9, 10, 11}};
Flatten[DeleteDuplicates[
Table[Select[reflist, MemberQ[#, list1[[i]]] &], {i, 1,
Length@list1}]], 1]
This methods works but is not efficient. my list1 could be more than half-million unique elements. I am seeking a more effective way to do it.
Select[reflist, Length@Intersection[list1, #] > 0 &]
. $\endgroup$