[Tutor] Combining dictionaries

Mike Cheponis mac at Wireless.Com
Tue Sep 6 22:22:36 CEST 2005


>Is this what you want ?
>
>c = dict(a)
>c.update(b)
>
>Pierre


>> Is there an easy way to combine dictionaries?
>>
>> a = {}
>> b = {}
>> 
>> a = {'a':'a', 'b':'b', 'c':'c'}
>> b = {'1':1, '2':2, '3':3}
>> c = a + b # doesn't seem to work
>> 
>> desired:
>> c = {'a':'a', 'b':'b', 'c':'c', '1':1, '2':2, '3':3}
>> 
>> Frank


No, that's not what he wants.

He wants c = a + b to work when a and b are dictionaries.

Why is Python broken in such an obvious way?

Thanks -Mike


More information about the Tutor mailing list