magical expanding hash
Steve Holden
steve at holdenweb.com
Tue Jan 17 15:38:51 EST 2006
Steven Bethard wrote:
> Paul Rubin wrote:
>
>>Hmm,
>>
>> x[a][b][c][d] = e # x is a "magic" dict
>>
>>becomes
>>
>> x.setdefault(a,{}).setdefault(b,{}).setdefault(c,{})[d] = e
>>
>>if I understand correctly. Ugh.
>
>
> 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()?
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