3

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?

Okazaki
  • 257
  • 1
  • 7

2 Answers2

3

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

eldo
  • 67,911
  • 5
  • 60
  • 168
2
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

kglr
  • 394,356
  • 18
  • 477
  • 896