标题: 遍历删除问题 [打印本页] 作者: 小庄酱 时间: 2019-11-5 16:50 标题: 遍历删除问题 a = [11, 22, 33, 44, 55, 66]
for i in a:
if i == 33 or i == 44:
a.remove(i)
print(a) # [11, 22, 44, 55, 66]
边遍历边删除,会漏删,解决方法如下
a = [11, 22, 33, 44, 55, 66]
b = [33, 44]
for i in b:
a.remove(i)
print(a)
# [11, 22, 55, 66]