Copying a key/value from one dictionary into another

dictionary, python

Solution

you want to use the `dict.update` method:

d1 = {'UID': 'A12B4', 'name': 'John', 'email': 'hi@example.com'}
d2 = {'UID': 'A12B4', 'other_thing': 'cats'}
d1.update(d2)

Outputs:

{'email': 'hi@example.com', 'other_thing': 'cats', 'UID': 'A12B4', 'name': 'John'}

From the Docs:

Update the dictionary with the key/value pairs from other, overwriting existing keys. Return None.

Problem

I have a dict with main data (roughly) as such: `{'UID': 'A12B4', 'name': 'John', 'email': 'hi@example.com}` and I have another dict like: `{'UID': 'A12B4', 'other_thing: 'cats'}` I'm unclear how to "join" the two dicts to then put "other_thing" to the main dict. What I need is: `{'UID': 'A12B4', 'name': 'John', 'email': 'hi@example.com, 'other_thing': 'cats'}` I'm pretty new to comprehensions like this, but my gut says there has to be a straight forward way.

Original source