Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can't seem to find the right set of patterns to independently match two different lists. Simplified versions of the lists are as follows:

list1 = {{2}, {2}, {20}, {2}, {10}}
list2 = {{2}, {2}, {2}, {2}, {2}, {2}}

In general, the second list will always have the same number inside the parentheses. They can have different lengths. Both will have just a single number inside the parentheses.

I am trying to find two patterns (p1,p2):

p1 = {{s_?NumericQ} ..};
p2 = {{_?NumericQ} ..};

Such that



{True, False, False, True}

My test patterns give {True, True, False, True} instead. I'm sure the answer is easy, but I just can't get it right...

share|improve this question
I get {False, True, True, True} when I evaluate your code and that is what I would have expected to get. – Mike Honeychurch Apr 18 '12 at 22:26
@MikeHoneychurch sorry must've copied it down wrong! – tkott Apr 18 '12 at 22:28
up vote 10 down vote accepted

The following patterns give the required output:

p1 = p : {{_?NumericQ} ..} /; ! Equal @@ p
p2 = {{s_?NumericQ} ..};

MatchQ[#[[1]], #[[2]]] & /@ Tuples[{{list1, list2}, {p1, p2}}]

==> {True, False, False, True}
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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