ContainsOnly

ContainsOnly[list1,list2]

yields True if list1 contains only elements that appear in list2.

ContainsOnly[list2]

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

Details and Options

Examples

open allclose all

Basic Examples  (2)

The first list contains only elements in the second list:

The first list contains elements not present in the second list:

Scope  (4)

This is one of the longest English words containing only vowels:

Use ContainsOnly in operator form:

The number of songs composed either by John Lennon or Paul McCartney, or by both together:

ContainsOnly works with associations:

Options  (2)

SameTest  (2)

By default, ContainsOnly 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 characters of a text, in lower case:

They are all letters and basic punctuation symbols:

Properties & Relations  (3)

Reversing the arguments of ContainsOnly is equivalent to using ContainsAll:

ContainsOnly[list1,list2] is equivalent to SubsetQ[list2,list1]:

ContainsOnly[{},list] always returns True:

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

Text

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

CMS

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

APA

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

BibTeX

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

BibLaTeX

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