Python多个dict进行合并
代码实现如下:
def merge_dicts(*dict_args): result = {} for item in dict_args: result.update(item) return result x1 = {'a':1, 'b':2} y1 = {'b':4, 'c':5} x2 = {'d':8, 'e':10} z3 = merge_dicts(x1,y1,x2) print(z3) 结果: {'a': 1, 'b': 4, 'c': 5, 'd': 8, 'e': 10}