lst=[1,2,2,12.8,'a','a','列表',2,'python',(2,'c'),{'name':'tom','age':18},'',True,[1,'a',3],{1,3,'a'}]
for i in lst:
if i == 2:
lst.remove(i)
使用for循环删除lst中的2,但是运行结果是:
[1, 12.8, 'a', 'a', '列表', 2, 'python', (2, 'c'), {'name': 'tom', 'age': 18}, '', True, [1, 'a', 3], {1, 'a', 3}]
为什么 元素 '列表' 后边的2,没有被删除?求各位大神解惑。