ContainsAny

ContainsAny[e1,e2]

yields True if e1 contains any of the elements of e2.

ContainsAny[e2]

is an operator form that yields True when the object to which it is applied contains any of the elements in e2.

Examples

open allclose all

Basic Examples  (2)

The first list contains some of the elements of the second list:

The first list does not contain any of the elements of the second list:

Scope  (5)

Take a random integer between 0 and 1000:

Check whether it contains any even digit:

Use ContainsAny in operator form:

Find tunnels in several countries:

Find the movies directed by Steven Spielberg whose cast includes any of the actors in the given list:

ContainsAny works with associations:

Options  (2)

SameTest  (2)

By default, ContainsAny considers elements to be the same if they are identical:

Changes of units are taken into account, as long as they represent the exact same quantity:

Numerical approximations are not considered as the same object:

Use Equal as the comparison function to have numerical tolerance:

String comparisons are case sensitive by default:

Convert to lower case before comparing:

Applications  (1)

Take the list of words in the English translation of the first volume of Don Quixote:

It contains the names of some of the modern European countries:

But it cannot contain countries in South America, which did not exist then:

Properties & Relations  (6)

ContainsAny[list1,list2] is equivalent to testing for nonempty intersection of the lists:

ContainsAny[list1,list2] is equivalent to IntersectingQ[list1,list2]:

ContainsAny is a symmetric function of its arguments. That is, ContainsAny[list1,list2]==ContainsAny[list2,list1]:

Negation of ContainsAny[list1,list2] is equivalent to ContainsNone[list1,list2]:

ContainsAny[list,{}] always returns False:

When working with lists of strings, there is case sensitivity:

Introduced in 2015
 (10.2)