 Occurrences - Maple Help

ListTools

 Occurrences
 number of occurrences in a list Calling Sequence Occurrences(x, L) Occurrences(x, L, f, opts) Parameters

 x - anything L - list f - (optional) boolean valued procedure opts - (optional) extra arguments to procedure f Description

 • The Occurrences(x, L) command returns the number of entries in the list L which equal x using a boolean comparison.
 If a function f is provided, equality is tested using f(x, L[i], opts) for each element ${L}_{i}$ in the list. Examples

 > $\mathrm{with}\left(\mathrm{ListTools}\right):$
 > $L≔\left[3.263,2.3,6.255,3.261,3.262\right]$
 ${L}{≔}\left[{3.263}{,}{2.3}{,}{6.255}{,}{3.261}{,}{3.262}\right]$ (1)
 > $\mathrm{Occurrences}\left(3.263,L\right)$
 ${1}$ (2)

The number of entries approximately equal to 3.263.

 > $\mathrm{Occurrences}\left(3.263,L,\mathrm{verify},\mathrm{float}\left(10,\mathrm{digits}=3\right)\right)$
 ${3}$ (3)

In the following example, the Occurrences command is used in conjunction with the ListTools:-FindRepetitions command to find the mode of a list with alpha-numeric values:

 > $\mathrm{L2}≔\left[1,2,3,4,3,4,b,b,a,c,c,c\right]:$
 > $\mathrm{SortedList}≔\mathrm{sort}\left(\mathrm{L2},\left(x,y\right)→\mathrm{ListTools}:-\mathrm{Occurrences}\left(y,\mathrm{L2}\right)<\mathrm{ListTools}:-\mathrm{Occurrences}\left(x,\mathrm{L2}\right)\right)$
 ${\mathrm{SortedList}}{≔}\left[{c}{,}{c}{,}{c}{,}{b}{,}{b}{,}{4}{,}{3}{,}{4}{,}{3}{,}{a}{,}{2}{,}{1}\right]$ (4)
 > $\mathrm{ListTools}:-\mathrm{FindRepetitions}\left(\mathrm{SortedList},\mathrm{ListTools}:-\mathrm{Occurrences}\left({\mathrm{SortedList}}_{1},\mathrm{L2}\right)-1\right)$
 $\left[{c}\right]$ (5)