title: Trying to compare two attributes of different classes in python, getting error "TypeError: list indices must be integers or slices, not Sheep"
body: <p>I'm working on a project where sheep roam around a plain and eat grass while wolves chase after the sheep. Everything worked fine until I got to the wolf AI trying to compare the sheep's location against their own. Here's my code for that is causing the error:</p>
  
  <pre><code>    def trackSheep(self, sheepList):
      sheepFound = 0#0 = false, 1 = true
      for s in sheepList:
          if sheepFound == 0:
              if sheepList[s].x == self.x and sheepList[s].y == self.y:
                  self.energy = self.energy + sheepList[s].energy
              else:
                  distanceToSheep = sheepList[s].x + sheepList[s].y
                  if distanceToSheep &lt; SHEEP_DETECTED_RANGE:
                      return [(sheepList[s].x,  sheepList[s].y)]
                      sheepFound = 1
          else:
              break
      if sheepFound == 0:
          return False
  </code></pre>
  
  <p>The error is on line 5 where I'm trying to see if the sheep's position is equal to that of the wolves. That is when it returns the error in the title. SheepList is an array consisting of multiple Sheep class objects. I'm calling the code in this function:</p>
  
  <pre><code>    def update(self, sheepList):#all logic for the wolves
      if self.isAlive():
          nearbySheep = self.trackSheep(sheepList)
          if not nearbySheep == False:
              self.huntSheep(nearbySheep)
          else:
              self.move()
      else:
          #add death behavior later
          self.color = p.Color("black")
  </code></pre>
  
  <p>which is triggered by my main function:</p>
  
  <pre><code>def main():
  framerate = 30
  p.init
  clock=p.time.Clock()
  screen=p.display.set_mode((WIDTH,HEIGHT))
  screen.fill((0,0,0))
  p.display.set_caption("Wolf Sheep Simulation")
  running = True
  #testSheep = s(5,3)
  #testSheep.draw(screen)
  SheepList = spawnInitialSheep()
  WolfList = spawnInitialWolves()
  testGrass = Grass(3,5)
  spawnGrass()
  
  while running:
      for event in p.event.get():
          if event.type == p.QUIT:
              running = False
      print(grassList)
      print(SheepList)
      for s in SheepList:
          s.update(grassList)
      for w in WolfList:
          w.update(SheepList)
  
      testGrass.draw(screen)
      #updte things
      #draw things
      for grassRow in grassList:
          for grassSquare in grassRow:
              grassSquare.update()
              grassSquare.draw(screen)
      for i in range (len(SheepList)):
          SheepList[i].draw(screen)
      for i in range (len(WolfList)):
          WolfList[i].draw(screen)
      p.display.flip()
      clock.tick(framerate)
  
  p.quit()
  </code></pre>
  
  <p>main()</p>
  
  <p>I'm assuming it's a simple formatting error, anyone know how to solve this?</p>