ListTools
Classify
classify the elements of a list, set, table, or rtable using a characteristic property
Calling Sequence
Parameters
Description
Examples
Compatibility
Classify(p, L, b1, ..., bn)
p
-
characteristic property defining a class
L
list, set, table, or rtable; the object containing elements to be classified
b1, ..., bn
(optional) extra arguments passed to p
The Classify(p, L, b1, ..., bn) function groups the elements of L into sets according to the characteristic property p. That is, it returns a table T with indices i such that T[i] is the set of elements e of L having value p(e, b1, ..., bn) = i.
If L is a table or rtable (such as an Array, Matrix, or Vector), the result is equivalent to applying this function to convert(L,list) with all other arguments the same. (See convert/list.)
The call Classify(p, L, b1, ..., bn) is mostly equivalent to ListTools[Categorize]((x, y) -> p(x)=p(y), L, b1, ..., bn) but more efficient. The form of the output is also different: Categorize returns a sequence of lists, while Classify returns a table of sets. On the other hand, Categorize is more general in that it accepts two-argument relations which can not necessarily be written in the form (x, y) -> p(x)=p(y) for some property p.
with⁡ListTools:
types≔Classify⁡whattype,Hello,1,2.,π,x,x+y,exp,world!:
map⁡print,op⁡eval⁡types:
string=Hello,world!
symbol=π,x
integer=1
procedure=exp
float=2.
`+`=x+y
number_of_distinct_prime_factors≔n↦nops⁡ifactors⁡n2:
npf30≔Classify⁡number_of_distinct_prime_factors,`$`⁡1..30:
indices⁡npf30,nolist
0,1,2,3
npf300
1
npf301
2,3,4,5,7,8,9,11,13,16,17,19,23,25,27,29
npf302
6,10,12,14,15,18,20,21,22,24,26,28
npf303
30
The ListTools[Classify] command was introduced in Maple 16.
For more information on Maple 16 changes, see Updates in Maple 16.
See Also
Array
convert/list
list
ListTools[Categorize]
Matrix
rtable
set
table
Vector
Download Help Document