Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
iteration
#2
The error was raised because the length of the list was changed. This is usually bad practice to iterate over changing list (using for-loop). However, I don't completely understand the problem. Are you always need to remove the first element of the list or you need to remove the previous element if the next is larger by 1?..
Try to rewrite the code using while loop, e.g.

index = 0
while index < len(your_list):
    # index += 1 etc.
    # remove items from your_list
If the list become empty, the while-loop will terminate.
Reply


Messages In This Thread
iteration - by d8a988 - Oct-23-2020, 09:12 PM
RE: iteration - by scidam - Oct-23-2020, 11:28 PM
RE: iteration - by jefsummers - Oct-24-2020, 03:47 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020