标签:浅拷贝 import imp 报错 删除 temp int 遍历字典 lan
temp = {‘name‘: ‘Mike‘, ‘age‘: ‘25‘, ‘shengao‘: 180, ‘weight‘: 80}
for key,value in temp.items():
del temp[key]
#RuntimeError: dictionary changed size during iteration
import copy
temp = {‘name‘: ‘Mike‘, ‘age‘: ‘25‘, ‘shengao‘: 180, ‘weight‘: 80}
copy_temp = copy.copy(temp)
for key,value in copy_temp.items():
del temp[key]
print(temp)#{}
dict遍历的时候删除dict中的值报错RuntimeError: dictionary changed size during iteration
标签:浅拷贝 import imp 报错 删除 temp int 遍历字典 lan
原文地址:https://www.cnblogs.com/venvive/p/13192579.html