Steven Bethard steven.bethard at gmail.com
Wed Jan 12 16:55:24 EST 2005

Rick Morrison wrote:
> Would there be any way to add a method to all dict objects that operated
> like the .update() method, but also returned a reference to the updated
> dict?

Are you looking for updated() to parallel sorted(), where sorted() 
returns a *new* list?  I doubt you'll be able to rally much support for 
a method that changes an object and returns a reference to it -- check 
the archives to see these kind of things getting rejected over and over.

Could you do something like:

py> import itertools
py> d1 = dict(a=1, b=2)
py> d2 = dict(c=3, d=4)
py> d3 = dict(itertools.chain(d1.iteritems(), d2.iteritems()))
py> d3
{'a': 1, 'c': 3, 'b': 2, 'd': 4}


More information about the Python-list mailing list