If I first do
from collections import defaultdict
then doing
defaultdict(lambda: "Default value")[7]
yields 'Default value'
. However, instead doing
defaultdict(default_factory=lambda: "Default value")[7]
results in
KeyError Traceback (most recent call last)
Cell In [28], line 1
----> 1 defaultdict(default_factory=lambda: "Default value")[7]
but according to the defaultdict
documentation, the first argument is default_factory
, so the two statements should be equivalent. So why do they behave differently?