magical expanding hash

Steven Bethard steven.bethard at gmail.com
Tue Jan 17 20:00:00 EST 2006


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
>>      http://wiki.python.org/moin/Python3%2e0Suggestions
>>
>> 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)
>>
>> STeVe
>>
> 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.

STeVe



More information about the Python-list mailing list