[Python-ideas] defaultdict factory argument

Zac Burns zac256 at gmail.com
Sun Jan 18 03:01:44 CET 2009

For one, it could be used to cache function calls.

I'm not sure how well defaultdict and WeakValueDictionary work
together (when combined/subclassed), but I can also imagine using a
class as the default_factory and using a defaultdict to return a new
instance of a class if none yet existed instantiated with the same
input parameters or returning the already existing one if one did
exist with those parameters.

Zachary Burns
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games

On Sat, Jan 17, 2009 at 5:44 PM, Chris Rebert <pyideas at rebertia.com> wrote:
> On Sat, Jan 17, 2009 at 5:35 PM, Zac Burns <zac256 at gmail.com> wrote:
>> I think defaultdict would be more useful if one could initialize it
>> with the option to have the key that is being looked up passed to
>> default_factory.
> While I don't disagree in principle, giving an example use-case would
> probably help.
> Cheers,
> Chris
> --
> Follow the path of the Iguana...
> http://rebertia.com
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

More information about the Python-ideas mailing list