Skip to content

CountDistinct

Counts the number of distinct elements in a list.

$ wo 'CountDistinct[{1, 2, 2, 3, 3, 3}]'
3

A second argument supplies a sameness test.

$ wo 'CountDistinct[{1, 2, 4}, Abs[#1 - #2] < 2 &]'
2