[Feature Request] dict.setdefault()

MRAB python at mrabarnett.plus.com
Tue Apr 12 00:59:33 CEST 2011


On 11/04/2011 23:44, Chris Angelico wrote:
> On Tue, Apr 12, 2011 at 8:41 AM, MRAB<python at mrabarnett.plus.com>  wrote:
>> I'm not sure that "setdefault" should take **kw args for this because
>> of its existing argument structure (key + optional value).
>>
>> A new method like "updatedefault" may be better, IMHO. It would act
>> like "update" except that it wouldn't overwrite existing values.
>
> Wouldn't x.updatedefault(y) be pretty much y.update(x) ?
>
I suppose it would, except that it wouldn't be in-place as such, and it
wouldn't be as efficient if you're wanting to default only a few
entries in a larger dict.



More information about the Python-list mailing list