Python's dict.pop(key[, default])
ignores the default value set by collections.defaultdict(default_factory)
as shown by the following code snippet:
from collections import defaultdict
d = defaultdict(lambda: 1)
d['a']
d['b'] = 2
print(d.pop('a')) # 1
print(d.pop('b')) # 2
print(d.pop('c', 3)) # 3
d.pop('e') # KeyError: 'e'
d
is a defaultdict(lambda: 1)
. d.pop('e')
causes a KeyError
. Is this intended? Shouldn't d.pop('e')
return 1
since that's the default value set by defaultdict
?