[Python-Dev] Proposal: defaultdict

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Feb 16 23:55:33 CET 2006

Guido van Rossum wrote:
> The first, required, argument to the
> constructor should be the default value.

I'd like to suggest that this argument be a function
for creating default values, rather than an actual
default value. This would avoid any confusion over
exactly how the default value is copied. (Shallow or
deep? How deep?)

In an earlier discussion it was pointed out that
this would be no less convenient for many common
use cases, e.g. in your example,

   d = defaultdict(list)

Also I'm not sure about the name "defaultdict".
When I created a class like this recently, I called
it an "autodict" (i.e. a dict that automatically
extends itself with new entries). And perhaps the
value should be called an "initial value" rather
than a default value, to more strongly suggest that
it becomes a permanent part of the dict.


More information about the Python-Dev mailing list