Collection Methods

collections.Counter.most_common()

Return up to n pairs ordered by decreasing count, breaking ties by first encounter. Omit n to include all entries.

Formal Syntax & Structure

python syntaxpython
counter.most_common(n=None)

Parameters & Attributes

NameTypeDescription
nintRequested count; see constraints in description.

Return Value

list[tuple]

The list[tuple] result described above.

Working Example

Example Snippetpython
import collectionsprint(collections.Counter("abac").most_common(2))
Python Reference