How To Merge Two Dictionaries With Common and Different Keys in Python?

  dictionary, function, key, merge, python

I am trying to make a function that will take two dictionaries and merge them together. When I search for the solution, I can find ones that only work for dictionaries that only have common keys, or only have different keys, but not a solution to both.

Example of what I want below.

Input

x = {"a": 91, "b": 102}
y = {"b": 8, "c": True}

Output

z = {"a": 91, "b": 110, "c": True}

Source: Python Questions

LEAVE A COMMENT