Pesky yaks, Please help

I have basically no idea where to start.

def removeByType(enemies, excludedType):
    tempList = []
    enemies = hero.findEnemies()
    for enemy in enemies:
        if enemy.id == "sand-yak":
            pass
    return tempList

while True:
    enemies = hero.findEnemies()
    enemies = removeByType(enemies, "sand-yak")
    enemy = hero.findNearest(enemies)
    if enemy:
        hero.attack(enemy)
        

All I have done is add

 if enemy.id == "sand-yak":

and

enemies = hero.findEnemies()

And I think those r wrong.

Level link. (sub only)
CodeCombat - Coding games to learn Python and JavaScript?

In this level, you are checking types, and you already have the type that you are excluding in the second parameter, so you need to make it this way:

if the type of enemy does not equal excludedType:
     append the enemy to the tempList

As for this, it isn’t necessary, enemies is already defined in the line below.

def removeByType(enemies, excludedType):
    tempList = []
    for enemy in enemies:
        if enemy.type != excludedType:
            hero.say("leave that yak alone!")
            +=1
        pass
    return tempList

while True:
    enemies = hero.findEnemies()
    enemies = removeByType(enemies, "sand-yak")
    enemy = hero.findNearest(enemies)
    if enemy:
        hero.attack(enemy)

It says indentation error on the +=1

And I feel like it takes more than a simple +=1 to append.

I recommend that you just find the nearest enemy, and if that enemy’s type is not equal to “sand-yak”, then attack the enemy. Rangers work best to attack from afar, this way you won’t have to move if you have a decent ranged weapon.

I don’t know rangers. I stick with warriors

It would work even if you use warriors.

I will try it. But later.

I tried again, ad this is my updated code.

def removeByType(enemies, excludedType):
    tempList = [0]
    for enemy in enemies:
        if enemy.type != excludedType:
            hero.say("leave that yak alone!")
            tempList +=1
        pass
    return tempList

while True:
    enemies = hero.findEnemies()
    enemies = removeByType(enemies, "sand-yak")
    enemy = hero.findNearest(enemies)
    if enemy:
        hero.attack(enemy)

I thought might of figured out what to append and how, but I apparently was wrong.

So this should be an empty array, no need to add the zero, brackets are enough.

To clear things out, the append works this way:

myList.append(myItem)

And i think that this is quite confusing, maybe you should name each one of them a different name.
For example:

enemies = hero.findEnemies()
notYaks = removeByType(enemies, "sand-yak")

THanks for those pointers, I think that mostly fixed the problem, and the append thing I shouldve seen, but anyways, It still attacks the yak, and I am not utilizing the notYak thing, and I think that that is the prob. ANy tips?

def removeByType(enemies, excludedType):
    tempList = []
    for enemy in enemies:
        if enemy.type != excludedType:
            hero.say("leave that yak alone!")
            tempList.append("sand-yak")
        pass
    return tempList

while True:
    enemies = hero.findEnemies()
    notYak = removeByType(enemies, "sand-yak")
    enemy = hero.findNearest(enemies)
    if enemy:
        hero.attack(enemy)

Yeah, we should fix that.

So this is unnecessary

and instead of enemy, replace both of them with notYak, but make sure to put that in a for-loop as notYak is a list

for myItem in myList:
     if myItem:
          hero.move(myItem.pos)