# Python 3.9 z = x | y # Python 3.5 z = {**x, **y} # Python <= 3.4 def merge_two_dicts(x, y): z = x.copy() # start with keys and values of x z.update(y) # modifies z with keys and values of y return z z = merge_two_dicts(x, y)