Python“延伸”为字典 [英] Python "extend" for a dictionary
本文介绍了Python“延伸”为字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
哪个是用另一个扩展字典的最佳方法?例如:
Which is the best way to extend a dictionary with another one? For instance:
>>> a = { "a" : 1, "b" : 2 }
>>> b = { "c" : 3, "d" : 4 }
>>> a
{'a': 1, 'b': 2}
>>> b
{'c': 3, 'd': 4}
寻找任何操作来获得这个避免循环的:
I'm looking for any operation to obtain this avoiding for
loop:
{ "a" : 1, "b" : 2, "c" : 3, "d" : 4 }
我想做一些类似的事情:
I wish to do something like:
a.extend(b) # This does not work
推荐答案
a.update(b)
这篇关于Python“延伸”为字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文