[Python-Dev] What if replacing items in a dictionary returns the new dictionary?

Oleg Broytman phd at phdru.name
Fri Apr 29 16:34:06 CEST 2011


Hi! Seems like a question for python-ideas mailing list, not for python-dev.

On Fri, Apr 29, 2011 at 10:27:46AM -0400, Roy Hyunjin Han wrote:
> It would be convenient if replacing items in a dictionary returns the
> new dictionary, in a manner analogous to str.replace().  What do you
> think?
> ::
> 
>     # Current behavior
>     x = {'key1': 1}
>     x.update(key1=3) == None
>     x == {'key1': 3} # Original variable has changed
> 
>     # Possible behavior
>     x = {'key1': 1}
>     x.replace(key1=3) == {'key1': 3}
>     x == {'key1': 1} # Original variable is unchanged

   You can implement this in your own subclass of dict, no?

Oleg.
-- 
     Oleg Broytman            http://phdru.name/            phd at phdru.name
           Programmers don't die, they just GOSUB without RETURN.


More information about the Python-Dev mailing list