On Wed, 12 Jan 2005 23:47:13 GMT, "Rick Morrison" <[EMAIL PROTECTED]> wrote:
>I could live with creating a new dict, sure (although it seems wasteful). I >realize that something like this probably doesn't stand a chance of ever >making it into the std library for what might be called "philosophical" >reasons. I just want it for me (my personal philosophy runs more to the >pragmatic -- well at least for coding). > >I suppose the in-place version would be more along the lines of: > >>>> def updated(d, updates): >... d.update(updates) >... return d >... >>>> [updated(d, {'c':3}) for d in [{'a':1, 'b':2}, {'x':10, 'y':'11'}]] >[{'a': 1, 'c': 3, 'b': 2}, {'y': '11', 'x': 10, 'c': 3}] > It's kind of a strange list comp, but I guess you're just illustrating something. But for this case you could just write >>> [d.update({'c':3}) or d for d in [{'a':1, 'b':2}, {'x':10, 'y':'11'}]] [{'a': 1, 'c': 3, 'b': 2}, {'y': '11', 'x': 10, 'c': 3}] taking advantage of normal d.update() returning None and so forcing the 'or' term. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list