# Why does MemberQ need {} around the expression? [closed]

Suppose I was trying to find out if the sequence 34 appeared in the digits of 344444. I tried to do this with MemberQ and get:

MemberQ[RealDigits[344444][[1]], {x___, 3, 4, y___}]


False

But if I add parentheses around the argument I get:

MemberQ[{RealDigits[344444][[1]]}, {x___, 3, 4, y___}]


True

RealDigits[344444][[1]] already gives me a list, why do I need to nest it inside another one? I thought it could be due to whether or not MemberQ checks the head of the list, but putting Heads -> True or Heads -> False does not alter the result.

-
I believe that MatchQ[RealDigits[344444][[1]], {x___, 3, 4, y___}] is what you want. –  David Carraher Jun 5 '13 at 1:57
Thanks for that, I see how that works. –  Andrew Ledesma Jun 5 '13 at 2:12

## closed as too localized by Oleksandr R., Sjoerd C. de Vries, Rojo, Artes, SilviaJun 5 '13 at 12:32

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

The answer is simple, you used the wrong function. If you want to find out whether some expression matches a pattern, you have to use MatchQ

MatchQ[RealDigits[344444][[1]], {x___, 3, 4, y___}]


MemberQ is used when you want to test whether any member of a list matches some pattern. If you put additional braces around your expression, then you make a list with one member you want to test. That's why it returns true with additional braces.

-
Thanks for that, that makes perfect sense. –  Andrew Ledesma Jun 5 '13 at 2:06