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
- In ContainsOnly[list1,list2], the listi must be lists of expressions, or representations of them, namely objects with heads like SparseArray, QuantityArray, Association or EntityClass.
- ContainsOnly[list1,list2,SameTesttest] applies test to each pair of elements in the listi to determine whether they should be considered the same.
- ContainsOnly[list2][list1] is equivalent to ContainsOnly[list1,list2].
Examples
open allclose allBasic Examples (2)
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:
Applications (1)
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:
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