Collection Classes
collections.Counter()
Count hashable values from an iterable or initialize counts from a mapping. Missing keys read as zero without insertion; counts may be zero or negative.
Formal Syntax & Structure
python syntaxpython
collections.Counter(iterable=None, /, **kwargs)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| iterable | iterable or mapping or None | Iterable of elements or mapping of elements to counts; omitted or None means no positional input. |
| kwargs | object | Additional keyword entries or arguments. |
Return Value
Counter
The Counter result described above.
Working Example
Example Snippetpython
import collectionsprint(dict(collections.Counter("aba")))