dict.updated

hanz hanzspam at yahoo.com.au
Wed Jan 12 20:28:32 EST 2005


Rick Morrison wrote:
> >>> [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}]

I don't really understand the use of this. Can you give a less toy
example? I'd probably just do

dicts = [{'a':1, 'b':2}, {'x':10, 'y':'11'}]
for d in dicts: d.update({'c':3})

This isn't really more typing or any clumsier IMO, so I can't see why
you'd want to use list comprehensions in this case.




More information about the Python-list mailing list