0

There is the following code:

def for_list(list_numbers):
    for n in list_numbers:
        try:
               ....
        except ...:
            list_numbers.remove(n)
               ....

Question: when hitting an exception, the element must be deleted, then the next element of the list must be accessed. How to do it?

Max Gacrux
  • 13
  • 4
  • you need to update your for loop to run on copy of list as `for n in list(list_numbers)` to handle updates in the length of list while removing element. Rest your `list_numbers.remove(n)` will work as intended – Moinuddin Quadri Jan 14 '21 at 20:40

1 Answers1

0

Try:

for n in list(list_numbers):
betontalpfa
  • 3,006
  • 1
  • 29
  • 54