A small proposed change to dictionaries' "get" method

Gareth McCaughan Gareth.McCaughan at pobox.com
Thu Aug 3 14:15:11 EDT 2000


Barry A. Warsaw wrote:

[I wrote:]
>> I suggest a minor change: another optional argument to
>> "get" so that
>>
>>     dict.get(item,default,flag)
> 
> Good idea, not so good solution.  Let's make it more explicit by
> adding a new method instead of a flag.  I'll use `put' here since this
> seems (in a sense) opposite of get() and my sleep addled brain can't
> think of anything more clever.  Let's not argue about the name of this
> method though -- if Guido likes the extension, he'll pick a good name
> and I go on record as agreeing with his name choice, just to avoid a
> protracted war.

I don't like d.put() because I'd expect

  d = {123:456}
  d.put(123,567)

to leave 567 in d[123]. In most cases, the method I'm proposing
will do exactly the same as the existing .get(); it's only when
there's no matching key that it's different.

I agree that names aren't desperately important, and I agree
that I'd rather have it in with a name I don't like than not
have it, and I agree that if Guido likes it he can call it what
he likes. :-)

-- 
Gareth McCaughan  Gareth.McCaughan at pobox.com
sig under construction



More information about the Python-list mailing list