python combine dicts code example
Example 1: python join dict
dict.update([other])
Example 2: join two dictionaries python
z = {**x, **y}
Example 3: python merge two dictionaries in a single expression
z = {**x, **y}
z = x | y
def merge_two_dicts(x, y):
z = x.copy()
z.update(y)
return z
Example 4: merge two dict python 3
z = {**x, **y}
Example 5: concatenate two dictionnaries python
d1.update(d2)
Example 6: python join dict
def mergeDict(dict1, dict2):
''' Merge dictionaries and keep values of common keys in list'''
dict3 = {**dict1, **dict2}
for key, value in dict3.items():
if key in dict1 and key in dict2:
dict3[key] = [value , dict1[key]]
return dict3
dict3 = mergeDict(dict1, dict2)
print('Dictionary 3 :')
print(dict3)