i have two lists of strings with unequal numbers of subelements in each.
i would like to remove from lis2 all instances where a pattern in lis1 appears in lis2:
lis1 = {{"a","b","c","d"}, {"w","x","y","z"}}
lis2 = {{"q","a","b","c","d","r"},{"j","k","l","m","n","o"}}
to give:
res = {"j","k","l","m","n","o"}
Thanks for ideas.
Addendum: Thanks for your replies!
I can't seem to make any of the suggestions work with the following lists:
lis1 = {{"a", "19", "b", "29"}, {"c", "42", "d", "13"}, {"e", "42", "f","10"}, {"g", "13", "h", "23"}, {"i", "14", "j", "26"}, {"k", "14", "l", "34"}, {"m", "7", "n", "77"}}
and
lis2 = {{DateObject[{2022, 9, 3}, "Day"], "w", "17", "x", "48", "AWAY", False}, {DateObject[{2022, 9, 3}, "Day"], "y", "0", "z", "55","AWAY", True}, {DateObject[{2022, 9, 3}, "Day"], "g", "13", "h","23", "AWAY", True}, {DateObject[{2022, 9, 3}, "Day"], "o", "13","p", "21", "AWAY", True}, {DateObject[{2022, 9, 3}, "Day"], "q","14", "r", "28", "AWAY", True}, {DateObject[{2022, 9, 3}, "Day"],"s", "1", "t", "2", "AWAY", True}}
The desired result is:
{{DateObject[{2022, 9, 3}, "Day"], "w", "17","x","48","AWAY", False}, {DateObject[{2022, 9, 3}, "Day"], "y", "0","z","55", "AWAY", True}, {DateObject[{2022, 9, 3}, "Day"], "o", "13", "p", "21", "AWAY", True}, {DateObject[{2022, 9, 3}, "Day"], "q", "14", "r", "28", "AWAY", True}, {DateObject[{2022, 9, 3}, "Day"], "s", "1", "t", "2", "AWAY", True}}
...in which the element containing the pattern {"g","13","h","23"} from lis1 is deleted from lis2.
Cases[lis2, Except[{___, PatternSequence["a", "b", "c", "d"], ___}]]
$\endgroup${"g","13","h","23"}
is deleted fromlis2
because it is present inlis1
. If you want to check for a complete signature match over a number of fields inlis2
then this could be another question. Right now any sub-sequence will result in a match, which is kind of limiting. In that case, I think the addendum can be posted as a new question. $\endgroup$DeleteCases[Alternatives @@ ({_, ##, ___} & @@@ lis1)] @ lis2
? $\endgroup$