【发布时间】:2013-12-04 10:13:15
【问题描述】:
如果 list2 中不存在,我需要从 list1 中删除所有不匹配的项目
List1 = ['dog', 'cat', 'bird']
List2 = ['dog']
for x in List2:
for y in List1:
if x!=y:
List1.remove(x)
从 list1 中删除一项后,此循环卡住了。 此操作的正确代码是什么
【问题讨论】: