dictionary python concatenate code example
Example 1: python merge dictionaries
dict1 = {'color': 'blue', 'shape': 'square'}
dict2 = {'color': 'red', 'edges': 4}
dict1.update(dict2)
Example 2: python merge dictionaries
def merge_dictionaries(a, b):
return {**a, **b}
def merge_dictionaries(a, b):
c = a.copy()
c.update(b)
return c
a = { 'x': 1, 'y': 2}
b = { 'y': 3, 'z': 4}
print(merge_dictionaries(a, b))
Example 3: concatenate two dictionnaries python
d1.update(d2)
Example 4: concat dicts python
d1={1:2,3:4}; d2={5:6,7:9}; d3={10:8,13:22}
d4 = dict(d1, **d2); d4.update(d3)