number of occurrences in a list - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Data Types : Tables, lists, and sets : ListTools Package : ListTools/Occurrences

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 Li in the list.

Examples

withListTools:

L:=3.263,2.3,6.255,3.261,3.262

L:=3.263,2.3,6.255,3.261,3.262

(1)

Occurrences3.263,L

1

(2)

The number of entries approximately equal to 3.263.

Occurrences3.263,L,verify,float10,digits=3

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&comma;x&comma;y&rarr;ListTools:-Occurrencesy&comma;L2<ListTools:-Occurrencesx&comma;L2

SortedList:=c&comma;c&comma;c&comma;b&comma;b&comma;4&comma;3&comma;4&comma;3&comma;a&comma;2&comma;1

(4)

ListTools:-FindRepetitionsSortedList&comma;ListTools:-OccurrencesSortedList1&comma;L21

c

(5)

See Also

list, ListTools, type[list], verify


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam