wang xuancong added the comment:
I agree with Mark Amery.
The reason why defaultdict still exists given that everything can be achieved
by subclassing the built-in dict is because of convenience. I suggest maybe
Python developer can put it into low priority instead.
--
nosy: +xuancon
Mark Amery added the comment:
I'm aware of __missing__. However, I don't think its existence is by itself a
knockdown argument against doing this. __missing__ also fulfils the need
satisfied by defaultdict, yet Python still has both - and the latter is almost
always more convenient to use wh
Raymond Hettinger added the comment:
The __missing__() method already fulfills this need:
class DoubleDict(dict):
def __missing__(self, key):
return key * 2
If desired, it can also add entries:
class DoubleDict(dict):
def __missing__(self, key):
se
New submission from Mark Amery :
There seems to be at least some demand for the ability to have the key being
accessed be passed to the factory function of a defaultdict. See e.g.
https://stackoverflow.com/q/2912231/1709587 (13k views) or previous enhancement
suggestion https://bugs.python.or