[issue38998] dict.setdefault (setdefault of dictionary)

Eric V. Smith report at bugs.python.org
Sun Dec 8 14:39:29 EST 2019


Eric V. Smith <eric at trueblade.com> added the comment:

Right. If you want the value only calculated once, then just call it once.

You might be interested in collections.defaultdict, which takes a factory function, and only calls it as needed.

----------
nosy: +eric.smith
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38998>
_______________________________________


More information about the Python-bugs-list mailing list