Dictionaries

Lad python at hope.cz
Wed Oct 18 12:13:43 EDT 2006


Tim Chase wrote:
> > How can I add two dictionaries into one?
> > E.g.
> > a={'a:1}
> > b={'b':2}
> >
> > I need
> >
> > the result {'a':1,'b':2}.
>
>  >>> a.update(b)
>  >>> a
> {'a':1,'b':2}
>
> -tkc

Thank you ALL for help.
However It does not work as I would need.
Let's suppose I have

 a={'c':1,'d':2}
 b={'c':2}
but
 a.update(b)
will make
{'c': 2, 'd': 2}

and I would need
{'c': 3, 'd': 2}

(because `c` is 1 in `a` dictionary and `c` is 2 in `b` dictionary, so
1+2=3)

How can be done that?
Thank you for the reply
L




More information about the Python-list mailing list