Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
1  
MemberQ[{1, 2, 3, 4, 5}, #] & /@ {2, 5}? –  Öskå Jun 2 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 at 12:23
    
You can still use Table: Table[MemberQ[{1, 2, 3, 4, 5}, i], {i, {2, 5}}]. –  Öskå Jun 2 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 at 13:06
    
I need if all of the elements of {2,5} are in the list. –  Kaisey Jun 2 at 13:47

1 Answer 1

Use Intersection for good performance.

Union[{2,5}] === Intersection[{2,5},{1,2,3,4,5}]
share|improve this answer

Your Answer

 
discard

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.