I have two lists as follow. The first is
p={{"j","d","x"},{"d","k","z"}}
and the second one is:
l={{"a","b","c"},{"a","x"},{"g","f","k"},{"d","a","k","o","l","z"},
{"j","a","d","o","x"}}
I want to delete those combination that exist in p
from l
, such that I get:
{{"a","b","c"},{"a","x"},{"g","f","k"}}
this is because {"d","a","k","o","l","z"}
contains {"d","k","z"}
and {"j","a","d","o","x"}
contains {"j","d","x"}
.
The way I did this so far is:
DeleteCases[l,_?(ContainsAll[{"j","d","x"}])]
DeleteCases[%,_?(ContainsAll[{"d","k","z"}])]
The above does the job, yet for a long list of p
this would be ineffective as one would have to use 100s of DeleteCases commands. I wonder if there is a clever way of doing this?
EDIT: As @rhermans suggested I am going to give a realistic example, let us make a list of all English words, separated by their letters as follow:
En = Alphabet["English"];
Characters[ToLowerCase[WordList[Language -> "English"]]];
Select[%, SubsetQ[En, ToLowerCase[#1]] &];
EN = Map[Sort, Map[DeleteDuplicates, %]];
We then make a list containing all the subsets of size 3 from the English alphabet, that is
l = Subsets[En, {3}]
Now for l[[1 ;; 1000]]
delete the cases in EN that contain l
.