I'm having a problem with ContainsAll
and I wonder if anyone can explain it. I have list1, a list of lists, and list2, a simple list. For example:
list1={{1,3,7},{4,5,6},{2,3,7},{3,6,7},{3,5,6},{1,4,7}}
list2={3,7}
Thinking of these as sets, suppose I want to find all the sets in list1 that have list2 as a subset. This works:
Select[list1,ContainsAll[list2]]
{{1,3,7},{2,3,7},{3,6,7}}
Another way to get the answer is:
Select[list1,SubsetQ[#,list2]&]
{{1,3,7},{2,3,7},{3,6,7}}
Now suppose I want all sets in list1 for which list 2 is not a subset. This works:
Select[list1,!SubsetQ[#,list2]&]
{{4,5,6},{3,5,6},{1,4,7}}
But negating ContainsAll
returns the empty set:
Select[list1,!ContainsAll[list2]]
{}
Any ideas? Is there something about the Attributes of ContainsAll
that I'm missing? The documentation says ContainsAll
is identical to SubsetQ
. But there seems to be a subtle difference between the two.