numbers = [2,8,6,12,13,9,5] for number in numbers: if number % 2 == 0 : numbers.remove(number) print(numbers)I wrote that code and run it .But it should delete all the even numbers in the list. But it left some of them .Please check it and give me a solution.
Why does modifying a list in a for loop not seem to work?
Why does modifying a list in a for loop not seem to work?
|
|
Messages In This Thread |
Why does modifying a list in a for loop not seem to work? - by umut3806 - Jul-22-2019, 08:20 PM
RE: That's so strange ... - by buran - Jul-22-2019, 08:23 PM
RE: Why is modifying a list in a for loop not seems to be working? - by umut3806 - Jul-22-2019, 08:25 PM
|
Users browsing this thread: 2 Guest(s)