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

Is there any way to ask a boolean question if the elements of the list {2,5} are in the list {1,2,3,4,5}?

share|improve this question
MemberQ[{1, 2, 3, 4, 5}, #] & /@ {2, 5}? – Öskå Jun 2 '14 at 12:21
Is there a way to code that without using shorthand notation. I've had some problems using shorthand notation when writing longer pieces of code; I'm not very experienced yet. – Kaisey Jun 2 '14 at 12:23
You can still use Table: Table[MemberQ[{1, 2, 3, 4, 5}, i], {i, {2, 5}}]. – Öskå Jun 2 '14 at 12:28
Do you need to test whether all elements of {2,5} are in the list or whether any one is present in the list? – Szabolcs Jun 2 '14 at 13:06
I need if all of the elements of {2,5} are in the list. – Kaisey Jun 2 '14 at 13:47

Use Intersection for good performance.

Union[{2,5}] === Intersection[{2,5},{1,2,3,4,5}]
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.