ContainsOnly

ContainsOnly[e1,e2]

yields True if e1 contains only elements that appear in e2.

ContainsOnly[e2]

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

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:

Introduced in 2015
 (10.2)