WOLFRAM

Tally[list]

tallies the elements in list, listing all distinct elements together with their multiplicities.

Tally[list,test]

uses test to determine whether pairs of elements should be considered equivalent, and gives a list of the first representatives of each equivalence class, together with their multiplicities.

Details

  • Tally[list] lists distinct elements in the order they appear in list.
  • Tally[list] is equivalent to Tally[list,SameQ].

Examples

open allclose all

Basic Examples  (2)Summary of the most common use cases

Obtain tallies for a list of symbols:

Out[1]=1

Count the elements of a list having the same head:

Out[1]=1

Scope  (3)Survey of the scope of standard use cases

Results are returned in order of first occurrence in the list:

Out[1]=1

Count the instances of randomly generated integers:

Out[1]=1

Elements of the list can be any expression:

Out[1]=1

Applications  (1)Sample problems that can be solved with this function

Count occurrences of characters in a string:

Out[2]=2

Properties & Relations  (5)Properties of the function, and connections to other functions

Elements with highest frequencies are given by Commonest:

Out[1]=1
Out[2]=2

A sorted Tally is equivalent to a list of counts for the Union:

Out[1]=1
Out[2]=2

Tally is a discrete analog of BinCounts:

Out[1]=1
Out[2]=2
Out[3]=3

Counts[list] returns an association in which values are the tallies of their keys:

Out[1]=1
Out[2]=2

Use the second argument of Tally to construct its corresponding by-function:

Count odd and even numbers in a list:

Out[2]=2
Wolfram Research (2007), Tally, Wolfram Language function, https://reference.wolfram.com/language/ref/Tally.html.
Wolfram Research (2007), Tally, Wolfram Language function, https://reference.wolfram.com/language/ref/Tally.html.

Text

Wolfram Research (2007), Tally, Wolfram Language function, https://reference.wolfram.com/language/ref/Tally.html.

Wolfram Research (2007), Tally, Wolfram Language function, https://reference.wolfram.com/language/ref/Tally.html.

CMS

Wolfram Language. 2007. "Tally." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Tally.html.

Wolfram Language. 2007. "Tally." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Tally.html.

APA

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

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

BibTeX

@misc{reference.wolfram_2025_tally, author="Wolfram Research", title="{Tally}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/Tally.html}", note=[Accessed: 06-June-2025 ]}

@misc{reference.wolfram_2025_tally, author="Wolfram Research", title="{Tally}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/Tally.html}", note=[Accessed: 06-June-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_tally, organization={Wolfram Research}, title={Tally}, year={2007}, url={https://reference.wolfram.com/language/ref/Tally.html}, note=[Accessed: 06-June-2025 ]}

@online{reference.wolfram_2025_tally, organization={Wolfram Research}, title={Tally}, year={2007}, url={https://reference.wolfram.com/language/ref/Tally.html}, note=[Accessed: 06-June-2025 ]}