magical expanding hash

Steve Holden steve at
Wed Jan 18 03:07:04 EST 2006

Steven Bethard wrote:
> Steve Holden wrote:
>>Steven Bethard wrote:
>>>Agreed.  I really hope that Python 3.0 applies Raymond Hettinger's 
>>>suggestion "Improved default value logic for Dictionaries" from
>>>This would allow you to make the setdefault() call only once, instead 
>>>of on every lookup:
>>>     class meh(dict):
>>>         def __init__(self, *args, **kwargs):
>>>             super(meh, self).__init__(*args, **kwargs)
>>>             self.setdefault(function=meh)
>>In fact, why not go one better and also add a "default" keyword 
>>parameter to dict()?
> It's not backwards compatible:
>  >>> dict(default=4)
> {'default': 4}
> And I use the **kwargs form of the dict constructor often enough to hope 
> that it doesn't go away in Python 3.0.
Nyargle. Thanks, you're quite right, of course: I was focussing on the 
list-of-pairs argument style when I wrote that. So the best we could do 
is provide a subtype, defaultdict(default, *args, *kw).

It still seems to me that would be better than having to call a method 
(though I don't object to the method for use if the defaut must change 
dynamically). Maybe I just liked Icon tables too much.

Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC           
PyCon TX 2006        

More information about the Python-list mailing list