1z = {**x, **y} #python 3.5 and above
2
3z = x | y #python 3.9+ ONLY
4
5def merge_two_dicts(x, y): # python 3.4 or lower
6 z = x.copy() # start with x's keys and values
7 z.update(y) # modifies z with y's keys and values & returns None
8 return z
1dict1 = {'color': 'blue', 'shape': 'square'}
2dict2 = {'color': 'red', 'edges': 4}
3
4dict1.update(dict2) #if a key exists in both, it takes the value of the second dict
5# dict1 = {'color': 'red', 'shape': 'square', 'edges': 4}
6# dict2 is left unchanged
1# list_of_dictionaries contains a generic number of dictionaries
2# having the same type of keys (str, int etc.) and type of values
3global_dict = {}
4
5for single_dict in list_of_dictionaries:
6 global_dict.update(single_dict)