A dataclass as a key to a defaultdict: KeyError
Solution 1:
collections.defaultdict(default_factory=int)
creates a default dict with no default value type, and one value (the type int
at the key "default_factory"
) because default_factory
can only be passed as positional argument. Any keyword arguments are considered key-value pairs for the dictionary:
defaultdict(None, {'default_factory': int})
You need to do collections.defaultdict(int)
, which produces defaultdict(int, {})