[Python-Dev] Re: A small proposed change to dictionaries' "get" method

Guido van Rossum guido@beopen.com
Thu, 03 Aug 2000 07:56:38 -0500


> "Barry A. Warsaw" wrote:
> > Good idea, not so good solution.  Let's make it more explicit by
> > adding a new method instead of a flag.

You're learning to channel me. :-)

> > 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.

But I'll need input.  My own idea was dict.getput(), but that's ugly
as hell; dict.put() doesn't suggest that it also returns the value.

Protocol: if you have a suggestion for a name for this function, mail
it to me.  DON'T MAIL THE LIST.  (If you mail it to the list, that
name is disqualified.)  Don't explain me why the name is good -- if
it's good, I'll know, if it needs an explanation, it's not good.  From
the suggestions I'll pick one if I can, and the first person to
suggest it gets a special mention in the implementation.  If I can't
decide, I'll ask the PythonLabs folks to help.

Marc-Andre writes:
> The following one-liner already does what you want:
> 
> 	d[word] = d.get(word, []).append('world')

Are you using a patch to the list object so that append() returns the
list itself?  Or was it just late?  For me, this makes d[word] = None.

--Guido van Rossum (home page: http://www.pythonlabs.com/~guido/)