ContainsAny

ContainsAny[list1,list2]

yields True if list1 contains any of the elements of list2.

ContainsAny[list2]

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

Details and Options

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:

Wolfram Research (2015), ContainsAny, Wolfram Language function, https://reference.wolfram.com/language/ref/ContainsAny.html.

Text

Wolfram Research (2015), ContainsAny, Wolfram Language function, https://reference.wolfram.com/language/ref/ContainsAny.html.

CMS

Wolfram Language. 2015. "ContainsAny." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ContainsAny.html.

APA

Wolfram Language. (2015). ContainsAny. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ContainsAny.html

BibTeX

@misc{reference.wolfram_2024_containsany, author="Wolfram Research", title="{ContainsAny}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/ContainsAny.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_containsany, organization={Wolfram Research}, title={ContainsAny}, year={2015}, url={https://reference.wolfram.com/language/ref/ContainsAny.html}, note=[Accessed: 21-November-2024 ]}