[Python-ideas] dict.setdefault_call(), or API variations thereupon

Michael Selik mike at selik.org
Fri Nov 2 21:34:20 EDT 2018


On Fri, Nov 2, 2018 at 5:25 PM Anders Hovmöller <boxed at killingar.net> wrote:

> Could you explain what the difference is between defaultdicts "factory
> which is unconditionally called when the key is missing" and "the default
> is evaluated only on need"?
>

The distinction was the motivation for this thread: setdefault requires a
constructed default instance as an argument, regardless of whether the key
is missing, whereas defaultdict's factory is only called if necessary. If
the key is present in a defaultdict, no default is constructed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20181102/9ca042cc/attachment.html>


More information about the Python-ideas mailing list