python - 在循环中追加和删除函数

时间:2017-09-17 11:35:37

标签: python list

birds = ["turkey", "hawk", "chicken", "dove", "crow"]
bird = []
for animal in birds:
    if animal.startswith("c"):
        birds.remove(animal)
    else:
        bird.append(animal)
print (birds)
print (bird)

为什么鸟和鸟的结果不同?!?!

0 个答案:

没有答案