Python Forum
Problem processing items in list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem processing items in list
#2
There are many issues with this code. The problem that you describe comes from modifying the list while iterating upon it. Let us simplify things by supposing that the list is
['foo bar', 'baz qux', 'login quux', 'static corge', 'grault garply']
When i=2, the 'login quux' is found and removed from the list. On the next iteration, one has i=3 but 'static corge' is never found because its index is now 2 instead of 3, so your algorithm could work if you started from the end of the list with
for i in range(len(vdescription_tokens) - 1, -1, -1): ...
Another obvious issue is that the code repeats itself a lot and it needs to be refactored to avoid this litany of if, elif, elif...
Reply


Messages In This Thread
Problem processing items in list - by PythonNewbee - Nov-07-2020, 11:16 AM
RE: Problem processing items in list - by Gribouillis - Nov-07-2020, 04:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  List processing speed Brettr 2 2,666 Jul-13-2018, 09:56 AM
Last Post: Brettr

Forum Jump:

User Panel Messages

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