[Python-Dev] defaultdict proposal round three

Steven Bethard steven.bethard at gmail.com
Tue Feb 21 00:14:27 CET 2006


On 2/20/06, Dan Gass <dan.gass at gmail.com> wrote:
> 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

Guido's currently backing "a subclass that implements __getitem__()
calling on_missing() and on_missing() ... calling default_factory
unless it's None".  I think for 90% of the use-cases, you don't need a
key argument.  If you do, you should subclass defaultdict and override
the on_missing() method.

STeVe
--
Grammar am for people who can't think for myself.
        --- Bucky Katt, Get Fuzzy


More information about the Python-Dev mailing list