添加pop方法后,为什么所有项目都不会附加到列表b [英] Why all of the items are not appending to list b after adding pop method
本文介绍了添加pop方法后,为什么所有项目都不会附加到列表b的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
a = [11,22,33,aa,bbb,9,cccc]
b = []
x = 0 >
for i in:
if isinstance(i,int):
b.append(i)
a。 pop(x)
x = x + 1
打印(a)
打印(b)
我尝试了什么:
在添加pop方法之前所有项目都附加但是在弹出后它们不是
a = [11, 22, 33, "aa", "bbb", 9, "cccc"]
b = []
x = 0
for i in a:
if isinstance(i,int):
b.append(i)
a.pop(x)
x = x + 1
print(a)
print(b)
What I have tried:
before adding pop method all of the items are appending but after pop they are not
推荐答案
在修改它(pop)时不要迭代列表(对于i ...)。
我变得笨拙。
Don't iterate a list (for i ...) while "modifying" it (pop).
"i" get whacky.
这篇关于添加pop方法后,为什么所有项目都不会附加到列表b的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文