python dictionary merge / mosaic dictionary

For the above python 3.5 version:

The best fastest way is the most elegant:

result_dict = {**dict_1, **dict_2}

 

For example :( dict representatives dictionary, that is, the dictionary)

dict_1 = {1: 1, 2: 2}
dict_2 = {3: 3, 4: 4}

# 更新 dict_1 / 合并 dict_1, dict_2
dict_1 = {**dict_1, **dict_2}

print('dict_1 =', dict_1)

 

 

 

Guess you like

Origin www.cnblogs.com/Alan-LJP/p/11833890.html