[Python-Dev] defaultdict proposal round three

Dan Gass dan.gass at gmail.com
Tue Feb 21 00:08:07 CET 2006

On 2/20/06, Raymond Hettinger <raymond.hettinger at verizon.net> wrote:
> An alternative is to have two possible attributes:
>   d.default_factory = list
> or
>   d.default_value = 0
> with an exception being raised when both are defined (the test is done
> when the
> attribute is created, not when the lookup is performed).
Why not have the factory function take the key being looked up as an
argument?  Seems like there would be uses to customize the default based on
the key.  It also forces you to handle list factory functions and constant
factory functions (amongst others) to be handled the same way:

d.default_factory = lambda k : list()
d.default_factory = lambda k : 0

Dan Gass
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20060220/2f99b73a/attachment.htm 

More information about the Python-Dev mailing list