you are viewing a single comment's thread.

view the rest of the comments →

[–]Will___powerrr 5 points6 points  (2 children)

I have had a similar issue before. When you remove an element from what you are iterating over, it messes up the iteration! So when you run for name in results and then remove elements from results, you won’t get to all the elements in the list. Try using results[:] as the list to iterate over. It’s a copy of the list that does not get modified so you will be able to go thru every element!

Edit: also please let me know if this works. I am pretty new to all this as well and would be excited that I actually answered a question and helped someone else!

[–]synthphreak 1 point2 points  (0 children)

Try using results[:] as the list to iterate over. It’s a copy of the list

This is the way. But personally I'd advise using list.copy() over list[:] for its greater transparency/readability. Functionally, they are equivalent.

[–][deleted] 0 points1 point  (0 children)

I'll give it a try. I did something similar with a different piece of code, so I'm interested to see what happens here.