python list浅拷贝踩坑
作者:互联网
如下:
data = {"a": [], "b": [1, 2, 3]}
a = data.get('a')
a.extend(data.get('b'))
print(data)
输出:
{'a': [1, 2, 3], 'b': [1, 2, 3]}
修复:
import copy
data = {"a": [], "b": [1, 2, 3]}
a = copy.deepcopy(data.get('a'))
a.extend(data.get('b'))
print(data)
输出:
{'a': [], 'b': [1, 2, 3]}
标签:输出,extend,get,python,list,print,拷贝,copy,data 来源: https://blog.csdn.net/weixin_43202635/article/details/122521849