在Python中附加字典

zur*_*fyx 2 python list

如何在Python中附加如下字典?

list1 = {'value1':1}
list2 = {'value2':2}

list1.append(list2)
Run Code Online (Sandbox Code Playgroud)

附加时:

'dict' object has no attribute 'append'
Run Code Online (Sandbox Code Playgroud)

那我怎么能加入这两个名单呢?

Owe*_*wen 6

这些是字典,而不是列表.

尝试 list1.update(list2)

update和append的语义不同,因为底层数据结构不同.字典中现有键的值将被参数字典中的值覆盖.

Python 数据结构教程的部分经历了这个以及更多内容.