 Search - Maple Help

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 Search( element, L ) SearchAll( element, L ) Parameters

 element - expression L - list Description

 • 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. Examples

 > $\mathrm{with}\left(\mathrm{ListTools}\right):$
 > $\mathrm{Search}\left("u",\left["a","u","v","b"\right]\right)$
 ${2}$ (1)
 > $\mathrm{Search}\left(2,\left[-5,-4,-2.2,3893,2,1,0,2,"a"\right]\right)$
 ${5}$ (2)
 > $\mathrm{SearchAll}\left(2,\left[-5,-4,-2.2,3893,2,1,0,2,"a"\right]\right)$
 ${5}{,}{8}$ (3)
 > $\mathrm{SearchAll}\left(\left[1,2\right],\left[\left[3,4\right],\left[5,6\right],\left[7,8\right]\right]\right)$