Skip to main content

← All terms · Standard library

collections.Counter

Dict subclass that counts hashable items: `Counter("hello")` → `{'l': 2, ...}`.

Learn this interactively:

Open lesson lesson-128

Related — Standard library

pathlib.PathObject-oriented filesystem paths. `Path(".").rglob("*.py")` beats `os.walk + os.itertoolsIterator building blocks — `chain`, `groupby`, `combinations`, `accumulate`. Lazfunctools.cacheMemoize a pure function with `@functools.cache`. Replaces hand-rolled dict cachidataclasses.fieldConfigure a dataclass attribute — mutable defaults, init/repr behavior. Use `fie