Help with not targeting an enemy in harrowland

My code isn’t working, it gets stuck on the line enemy = self.findNearest(toattack) in the while True: loop. Any ideas?

def trylure():
    self.moveXY(22, 36)
    self.moveXY(37,36)
enemies = self.findEnemies()
archers = [zenemy for zenemy in enemies if zenemy.type == "archer"]

toattack = []
for archer in archers: 
    self.attack(archer)
for thetype in enemies:
    if thetype.type != 'sand-yak':
        if thetype.type != 'archer':
            toattack.append(thetype)
while True:
    enemy = self.findNearest(toattack)
    while enemy.health > 0:
        self.attack(enemy)

transfer all in the main loop
it will solve all your problems

archers = [zenemy for zenemy in enemies if zenemy.type == "archer"]

At the time of execution, not all archers does exist

for thetype in enemies:
    if thetype.type != 'sand-yak':
        if thetype.type != 'archer':
            toattack.append(thetype)

if you try focus hero here
there also soldiers

enemy = self.findNearest(toattack)

you kill the nearest at the time of execution

enemies = self.findEnemies() 

and that is all