I wrote a for
loop that supposedly removes any elements that fits the description.
Example:
for tag in tags:
if tag.lower() in ['ex1', 'ex2', 'ex3']:
tags.remove(tag)
My tags
would look like ['EX1', 'EX2', 'ex1', 'ex2', 'ex3', 'ex4', 'ex5']
and I expect to keep only ex4
and ex5
What I noticed is that the for loop would skip some elements, giving me results like ['EX2', 'ex2', 'ex4', 'ex5']
I suspect this being indexing issue, but I'm not sure if that's really the case.
I ended up using a list comprehension, which does the job correctly, but I just want to understand the true reason behind the unexpected behavior.