ListTools
Occurrences
number of occurrences in a list
Calling Sequence
Parameters
Description
Examples
Occurrences(x, L)
Occurrences(x, L, f, opts)
x
-
anything
L
list
f
(optional) boolean valued procedure
opts
(optional) extra arguments to procedure f
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 Li in the list.
withListTools:
L≔3.263,2.3,6.255,3.261,3.262
Occurrences3.263,L
1
The number of entries approximately equal to 3.263.
Occurrences3.263,L,verify,float10,digits=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:
L2≔1,2,3,4,3,4,b,b,a,c,c,c:
SortedList≔sortL2,x,y↦ListTools:−Occurrencesy,L2<ListTools:−Occurrencesx,L2
SortedList≔c,c,c,b,b,4,3,4,3,a,2,1
ListTools:-FindRepetitionsSortedList,ListTools:-OccurrencesSortedList1,L2−1
c
See Also
type/list
verify
Download Help Document