首页 > 解决方案 > 词典链接

问题描述

我是字典新手,发现以下内容非常令人困惑。

resume = [{'name': 'New', 'value1': 'dfgdf'}, {'name': 'garry', 'value1': 'hhhhhh'}]
current = resume[0]
current['name'] = '24/7 link was not requested...'
print(resume)

回报:

[{'name': '24/7 link was not requested...', 'value1': 'dfgdf'}, {'name': 'garry', 'value1': 'hhhhhh'}]

为什么在没有请求resume和之间的永久/连续链接时会发生这种情况?......以及如何更改它以便更新为新的/请求的字符串值而不是 resumecurrentcurrent['name']

标签: pythonpython-3.xdictionary

解决方案


尝试改变

current = resume[0]

current = resume[0].copy()

这应该创建一个新的字典对象。


推荐阅读