how to join two Dictionary together?

Mikael Olofsson mikael at isy.liu.se
Tue Aug 30 10:58:54 EDT 2005


DENG wrote:
> dict1={...something...}
> dict2={...somethind else ..}
> dict1 + dict2
> 
> that's does works ..:(, it's not like List...
> anyone can tell me how to get it?

I would do the following in most cases.

 >>> dict1={'a':'A'}
 >>> dict2={'b':'B'}
 >>> dict3=dict1.copy()
 >>> dict3
{'a': 'A'}
 >>> dict3.update(dict2)
 >>> dict3
{'a': 'A', 'b': 'B'}

HTH
/Mikael Olofsson

Universitetslektor (Senior Lecturer [BrE], Associate Professor [AmE])
Linköpings universitet

-----------------------------------------------------------------------
E-Mail:  mikael at isy.liu.se
WWW:     http://www.dtr.isy.liu.se/en/staff/mikael
Phone:   +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
-----------------------------------------------------------------------
Linköpings kammarkör: www.kammarkoren.com   Vi söker tenorer och basar!



More information about the Python-list mailing list