I am trying to take out numbers from a list that contains both numbers and strings and move them into a new list.
x = 0
list1 = ["a", "b", "c", 1, 2, 3, 4, 5, 6, "d", 7]
list2 = []
for item in list1:
if isinstance(item, int):
list2.append(item)
list1.pop(x)
x += 1
list1
list2
The result is not what I expect:
list1
['a', 'b', 'c', 2, 4, 6, 'd']
list2
[1, 3, 5, 7]
I don't understand why the condition is false for the 2nd consecutive numbers from the list, is it because of the way is declared?