On this page
typing.DefaultDict
Prev: typing.dataclass_transform | Up: typing | Next: typing.Deque
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.DefaultDict
Tags: #public #python3 #stdlib #typing
Import
import typing
from typing import DefaultDict
Signature & Overview
typing.DefaultDict(*args, **kwargs)
Deprecated alias to collections.defaultdict.
Usage
from collections import defaultdict
from typing import DefaultDict
groups: DefaultDict[str, list[int]] = defaultdict(list)
groups["a"].append(1)
assert groups["a"] == [1]
Gotchas
- Deprecated alias in Python 3.9+: Use
collections.defaultdict[str, list[int]]directly.
REPL Inspect
from typing import DefaultDict
help(DefaultDict)
Linked from
Related notes
- tuts/python3/stdlib_module/typing/dataclass_transform Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Deque Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/typing/AbstractSet Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Annotated Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Any Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_never Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_type shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncContextManager shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncGenerator shared tags: #stdlib, #typing