Counts

Counts[list]

gives an association whose keys are the distinct elements of list, and whose values give the number of times those elements appear in list.

Counts[list,elems]

gives an association whose keys are the distinct elements in elems, and whose values give the number of times those elements appear in list.

Details

  • Counts[list] gives an association whose keys are in the same order as they first occur as elements of list. »
  • Counts[list,elems] gives an association whose keys are in the same order as they first occur as elements of elems.

Examples

open allclose all

Basic Examples  (2)

Count occurrences of unique elements in a list:

Count occurrences of the elements a, b, c and d in a list:

Scope  (1)

Count occurrences in a random list of 0s and 1s:

Repeat, but giving the count of 1s before the count of 0s:

Properties & Relations  (5)

Counts[list] lists elements by the order in which the first appear in list:

Counts[list,elems] lists elements by the order in which the first appear in elems:

Counts[list,elems] will contain totals for all elements in elems, even if they do not appear in list:

CountsBy[list,f] is effectively Counts[Map[f,list]]:

Counts examines literal values:

Count tallies elements matching a pattern:

Wolfram Research (2014), Counts, Wolfram Language function, https://reference.wolfram.com/language/ref/Counts.html (updated 2025).

Text

Wolfram Research (2014), Counts, Wolfram Language function, https://reference.wolfram.com/language/ref/Counts.html (updated 2025).

CMS

Wolfram Language. 2014. "Counts." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/Counts.html.

APA

Wolfram Language. (2014). Counts. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Counts.html

BibTeX

@misc{reference.wolfram_2024_counts, author="Wolfram Research", title="{Counts}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/Counts.html}", note=[Accessed: 20-January-2025 ]}

BibLaTeX

@online{reference.wolfram_2024_counts, organization={Wolfram Research}, title={Counts}, year={2025}, url={https://reference.wolfram.com/language/ref/Counts.html}, note=[Accessed: 20-January-2025 ]}