Raymond Hettinger <raymond.hettin...@gmail.com> 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): self[key] = value = key * 2 return value ---------- nosy: +rhettinger resolution: -> rejected stage: -> resolved status: open -> closed _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38315> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com