Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 26-Jul-18 10:55am

1 solution

Don't iterate a list (for i ...) while "modifying" it (pop).

"i" get whacky.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900