Python合并两个字典,python合并字典,Python合并两个字典


Python合并两个字典代码:

a = {1:1, 2:2}b = {1:2, 3:3}#way 1print dict(a.items()+b.items())#way 2#fail (producing a TypeError) in Python 3.2, and in current versions of Jython, PyPy and IronPython: for those versions of Python, when passing a dict with the ** notation, all the keys of that dict should be strings.print dict(a, **b) #way 3c = a.copy()c.update(b)print c

评论关闭