python - 词典链接
问题描述
我是字典新手,发现以下内容非常令人困惑。
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
和之间的永久/连续链接时会发生这种情况?......以及如何更改它以便更新为新的/请求的字符串值而不是 resume。current
current['name']
解决方案
尝试改变
current = resume[0]
至
current = resume[0].copy()
这应该创建一个新的字典对象。
推荐阅读
- sql - SQL - 当存在具有“name”列的类似表时,调用列“name”或“client_name”更好吗?
- c# - 为什么发送数据到服务器时会出现问号?
- typescript - 将方法参数声明为与附加属性的接口
- c# - 如何将 SetAlphamaps 设置为一个特定的纹理?
- php - 为什么curl在php中做成函数时不起作用
- xcode - iOS 13 - 以编程方式以全屏模式将新故事板 nv/vc 转为模态
- python-3.x - 使用分页抓取所有 href 链接
- scala - 使用 Spark 将 yyyyMMdd 转换为日期
- python-3.x - 为什么以下代码的运行时间不同?请详细说明
- android - 使用带有 Chrome 自定义选项卡的 OkHttpClient