3
$\begingroup$

I have a list of two-element lists

{{a,b},{c,d},{x,y}}

I can use MemberQ to test if one of these lists is present, for example

In[54]:= MemberQ[{{a, b}, {c, d}, {x, y}}, {c, d}]

Out[54]= True

I would like to test if at least two of the lists belong to this bigger list, for example if {a,b} and {c,d} belong to the bigger list. I cannot find a find a way to do this, and MemberQ doesn't work.

Any suggestions?

$\endgroup$
2
$\begingroup$
ContainsAll[{{a, b}, {c, d}, {x, y}}, {{c, d}, {a, b}}]
SubsetQ[{{a, b}, {c, d}, {x, y}}, {{c, d} , {a, b}}]
Union @ # === Union @ ## &[{{a, b}, {c, d}, {x, y}}, {{c, d}, {a, b}}]
Intersection @ ## === Sort @ #2 &[{{a, b}, {c, d}, {x, y}}, {{c, d}, {a, b}}]

all give

True

$\endgroup$
3
$\begingroup$

For Version 10 and earlier:

list = {{a, b}, {c, d}, {x, y}};

And @@ Map[MemberQ[list, #] &, {{a, b}, {c, d}}]

True

And @@ Map[MemberQ[list, #] &, {{a, b}, {p, q}}]

False

And @@ Map[MemberQ[list, #] &, {{a, b}, {c, d}, {x, y}, {a, b}}]

True

Or

Length @ Union[list, {{a, b}, {p, q}}] == Length @ list

False

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.