ListTools
Search
search for an occurrence of an element in a list
SearchAll
search for all occurrences of an element in a list
Calling Sequence
Parameters
Description
Examples
Search( element, L )
SearchAll( element, L )
element
-
expression
L
list
The Search(element, L) calling sequence searches for element in the list L. If element does not occur as an element of L, then 0 is returned. Otherwise, the index of the first occurrence of element in L is returned.
Note: The list L is not assumed to be sorted, so the time taken by this procedure may be linear in the length of the list.
The SearchAll(element, L) calling sequence finds all occurrences of element in L. It returns an expression sequence of the indices of occurrences of element in L. This expression sequence is NULL if element does not occur in L.
In order to search for elements satisfying a certain predicate, use SelectFirst.
with⁡ListTools:
Search⁡u,a,u,v,b
2
Search⁡2,−5,−4,−2.2,3893,2,1,0,2,a
5
SearchAll⁡2,−5,−4,−2.2,3893,2,1,0,2,a
5,8
SearchAll⁡1,2,3,4,5,6,7,8
See Also
ListTools[BinarySearch]
ListTools[SelectFirst]
StringTools[Search]
StringTools[SearchAll]
Download Help Document