Trying to remove Tuples based on var [0] from the list of tuples, are some of them left?

I can’t understand why this section of the code does not remove the “tactics” (tuples) from the list [tuples ()]

def _cleanup(self):
    for tactic in self._currentTactics:
        if tactic[0] == "Scouting":
            if tactic[1] in self._estimate.currently_visible:
                self._currentTactics.remove(tactic)
        elif tactic[0] == "Blank":
            self._currentTactics.remove(tactic)
        elif tactic[0] == "Scout":
            self._currentTactics.remove(tactic)

Screenshots of my IDE (pydev) with additional debugging information are available at: http://imgur.com/a/rPVnl#0

EDIT: Fixed a bug that I noticed and improved. To clarify, the "Form" is removed, the "Scouting" is deleted if necessary, and the tactics of the "Scout" is NOT deleted afaik.

+3
source share
1 answer

You remove members from the list during the replay. By doing this, you will skip some items in the list. You need to iterate over a copy of the list instead.

Edit:

for tactic in self._currentTactics:

at

for tactic in self._currentTactics[:]:
+3
source

All Articles