[Tutor] Is there an easy way to combine dictionaries?
Byron
byron at christianfreebies.com
Tue Sep 6 15:43:22 CEST 2005
Lane, Frank L wrote:
> Is there an easy way to combine dictionaries?
Hi Frank,
Yes, there is -- please see the "addDict" method that I have provided below:
Byron
---
def addDicts(a, b):
c = {}
for item in a:
c[item] = a[item]
for item in b:
c[item] = b[item]
return c
a = {'a':'a', 'b':'b', 'c':'c'}
b = {'1':1, '2':2, '3':3}
c = addDicts(a, b)
print c
More information about the Tutor
mailing list