[Python-Dev] Proposal: defaultdict

Steve Holden steve at holdenweb.com
Sun Feb 19 04:38:39 CET 2006


Martin v. Löwis wrote:
> Guido van Rossum wrote:
> 
>>Feedback?
> 
> 
> I would like this to be part of the standard dictionary type,
> rather than being a subtype.
> 
> d.setdefault([]) (one argument) should install a default value,
> and d.cleardefault() should remove that setting; d.default
> should be read-only. Alternatively, d.default could be assignable
> and del-able.
> 
The issue with setting the default this way is that a copy would have to 
be created if the behavior was to differ from the sometimes-confusing 
default argument behavior for functions.


> Also, I think has_key/in should return True if there is a default.
> 
It certainly seems desirable to see True where d[some_key] doesn't raise 
an exception, but one could argue either way.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/



More information about the Python-Dev mailing list