Problem with clearing lists?

So I have some code:

def detectShots(self, task):
        if self.notifier.getNumEntries() >= 1:
            self.dr = True
            for i in self.notifier.getEntries():
                if "zombie" in str(i):
            for zombieName in self.zombiesHit:
                dst = zombieName.getDistance(
                zombieName.setPythonTag("dst", dst)

            lengthDst = len(self.distanceZombies)

            shortestDistance = min(self.distanceZombies)
            zombieNName = shortestDistance
            for x in self.zombiesHit:
                if x.getPythonTag("dst") == (shortestDistance):
                    self.zombie_shot(x.getPythonTag("HP"), x, x.getPythonTag("COLNODE"))


        return task.cont

And when I run it (and shoot the zombie), it says:

dst = zombieName.getDistance(
AssertionError: !is_empty() at line 1834 of panda/src/pgraph/nodePath.cxx

This means I haven’t deleted the zombie from the list yet, right? How? Clear is a method I made.

def clear(self, list):
        if list:
            for i in list:

Tell me if I need to clarify anything, I’m in a hurry.

Thanks a lot!

In general it is never a good idea to remove items from a list while iterating over it. If you remove element 0 from the list on the first iteration, then on the second iteration element 1 will actually be element 2 of the original list because they have all shifted over by one each time you remove an item. This means the second item in the list would never be removed.

The best way to clear a list is to use the del statement.

del self.distanceZombies[:]
del self.zombiesHit[:]

The [:] at the end is telling it to delete elements from the beginning to the end of the list.