β All terms Β· Standard library
collections.defaultdict
Dict that auto-creates missing keys with a factory: `defaultdict(list)` returns `[]` for any new key. Replaces `if k not in d: d[k] = []`-style code in counters and grouping.
counts = defaultdict(int) counts[word] += 1
Learn this interactively:
Open lesson iv-43 βRelated β Standard library
pathlib.PathObject-oriented filesystem paths. `Path(".").rglob("*.py")` beats `os.walk + os.β¦collections.CounterDict subclass that counts hashable items: `Counter("hello")` β `{'l': 2, ...}`.itertoolsIterator building blocks β `chain`, `groupby`, `combinations`, `accumulate`. Lazβ¦functools.cacheMemoize a pure function with `@functools.cache`. Replaces hand-rolled dict cachiβ¦dataclasses.fieldConfigure a dataclass attribute β mutable defaults, init/repr behavior. Use `fieβ¦