update certain key-value pairs of a dict from another dict

Daiyue Weng daiyueweng at gmail.com
Fri Nov 11 06:17:14 EST 2016


Hi, I have two dicts, e.g.

dict1 = {'A': 'a', 'B': 'b', 'C': 'c'}
dict2 = {'A': 'aa', 'B': 'bb', 'C': 'cc'}

I am wondering how to update dict1 using dict2 that

only keys 'A' and 'B' of dict1 are udpated. It will result in

dict1 = {'A': 'aa', 'B': 'bb', 'C': 'c'}

cheers



More information about the Python-list mailing list