On 2016-11-11 13:29, Peter Otten wrote:
> The same using update(), with a generator expression that avoids
> the intermediate dict:
>
> >>> dict1 = {'A': 'a', 'B': 'b', 'C': 'c'}
> >>> dict1.update((k, dict2[k]) for k in desired & dict1.keys() &
> dict2.keys())
Huh. Handy to file that new knowl
Tim Chase wrote:
> On 2016-11-11 11:17, Daiyue Weng wrote:
>> 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
On 2016-11-11 11:17, Daiyue Weng wrote:
> 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'}
Use
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
--
https://mail.python.