0
full_list = [1, 2, 3, "four", "five", "six"]
empty_list = []

for numbers in full_list:
    if type(numbers) == int:
        empty_list.append(numbers)
        full_list.remove(numbers)
        
print(full_list)
print(empty_list)

When I run the program, it gives the following output:

[2, 'four', 'five', 'six'] [1, 3]

Nali
  • 1
  • 1
  • 3
    removing from the list you are iterating is a bad idea. – trincot Nov 13 '22 at 14:37
  • Yes, change the for-loop header to `for numbers in list(full_list)`. This will give you a different array to iterate over. It's a miracle that your code didn't raise errors by the way ;) – C-3PO Nov 13 '22 at 14:39

0 Answers0