[Python-Dev] Proposal: defaultdict
Terry Reedy
tjreedy at udel.edu
Sun Feb 19 06:13:20 CET 2006
> Quoting skip at pobox.com:
>> The only question in my mind is whether or not getting a non-existent
>> value
>> under the influence of a given default value should stick that value in
>> the
>> dictionary or not.
It seems to me that there are at least two types of default dicts, which
have opposite answers to that question.
One is a 'universal dict' that maps every key to something -- the default
if nothing else. That should not have the default ever explicitly entered.
Udict.keys() should only give the keys *not* mapped to the universal value.
Another is the accumlator dict. The default value is the identity (0, [],
or whatever) for the type of accumulation. An adict must have the identity
added, even though that null will usually be immedially incremented by +=1
or .append(ob) or whatever.
Guido's last proposal was for the default default_dict to cater to the
second type (and others needing the same behavior) while catering to the
first by making the default fill-in method over-rideable.
It we go with, for instance, wrappers in the collections module instead of
modification of dict, then perhaps there should be at least two wrappers
included, with each of these two behaviors.
Terry Jan Reedy
More information about the Python-Dev
mailing list