magical expanding hash
Steve Holden
steve at holdenweb.com
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
>>> 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.
>
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.
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-list
mailing list