CountDistinctBy[{e1,e2,…},f]
gives the number of distinct values of f[ei] that occur.
represents an operator form of CountDistinctBy that can be applied to an expression.
CountDistinctBy
CountDistinctBy[{e1,e2,…},f]
gives the number of distinct values of f[ei] that occur.
represents an operator form of CountDistinctBy that can be applied to an expression.
Details
- CountDistinctBy[<|key1val1,key2val2,…|>, f] counts the distinct values of f[vali].
- CountDistinctBy[f][expr] is equivalent to CountDistinctBy[expr,f].
Examples
open all close allBasic Examples (2)
Count the number of distinct first parts:
CountDistinctBy[{{a, x}, {a, y}, {b, z}}, First]Count the number of distinct first parts of the values of an association:
CountDistinctBy[<|a -> {a, x}, b -> {a, y}, c -> {b, z}|>, First]Use the operator form of CountDistinctBy:
CountDistinctBy[First] @ {{a, x}, {a, y}, {b, z}}Applications (1)
Properties & Relations (2)
CountDistinctBy[list,f] gives the same result as CountDistinct[f/@list]:
CountDistinctBy[{1, 2, 3, -2, -3}, Abs]CountDistinct[Abs /@ {1, 2, 3, -2, -3}]CountDistinctBy[list,f] applies the transformation f to each element, then compares the results:
CountDistinctBy[{{a, x}, {a, y}, {b, z}}, First]CountDistinct[list,test] applies test to two elements to determine if they are equivalent:
CountDistinct[{{a, x}, {a, y}, {b, z}}, First[#] == First[#2]&]See Also
Related Guides
History
Text
Wolfram Research (2014), CountDistinctBy, Wolfram Language function, https://reference.wolfram.com/language/ref/CountDistinctBy.html.
CMS
Wolfram Language. 2014. "CountDistinctBy." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CountDistinctBy.html.
APA
Wolfram Language. (2014). CountDistinctBy. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CountDistinctBy.html
BibTeX
@misc{reference.wolfram_2026_countdistinctby, author="Wolfram Research", title="{CountDistinctBy}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/CountDistinctBy.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_countdistinctby, organization={Wolfram Research}, title={CountDistinctBy}, year={2014}, url={https://reference.wolfram.com/language/ref/CountDistinctBy.html}, note=[Accessed: 12-June-2026]}