title: Python: Why is my for loop not iterating over the entire list?
body: <p>So I have an "Object Class" that looks like this (details abstracted away for readability)</p>
  
  <pre><code>class Object: #this is a generic object: the player, a monster, an item, the stairs... it is always represented by a character on the screen.
  def __init__(self, *args, **kwargs):
      #Default Variables
      self.always_visible = False
      self.blocks = False
      self.inventory = []
  
      for k, v in kwargs.iteritems():
          setattr(self, k, v)
  
      if TexturePack == True:
          self.color = libtcod.white
  
      #Components
      #if self.fighter:  #let the fighter component know who owns it
      try: self.fighter.owner = self 
      except: self.fighter = None
  
      #if self.ai:  #let the AI component know who owns it
      try: self.ai.owner = self 
      except: self.ai = None
  
      #if self.item: #let the Item component know who owns it
      try: self.item.owner = self
      except: self.item = None
  
      #if self.equipment:  #let the Equipment component know who owns it
      try: 
          self.equipment.owner = self
          #there must be an Item component for the Equipment component to work properly
          self.item = Item()
          self.item.owner = self
      except: self.equipment = None
  </code></pre>
  
  <p>and I am creating a monster with this code</p>
  
  <pre><code>            #Create Goblin
              fighter_component = Fighter(hp=10, power=8, defense=0, xp=10, death_function=monster_death)
              ai_component = BasicMonster()
              monster = Object(x=player.x+3, y=player.y, char='g', name='Goblin', color=libtcod.lightest_green,
                  blocks=True, fighter=fighter_component, ai=ai_component)
  
              #Populate Goblin's Equipment
              monster.inventory = [
                  Object( x=0, y=0, char='-', name='Dagger', color=libtcod.cyan, equipment=Equipment(slot='right hand', power_bonus=2) ),
                  Object( x=0, y=0, char='!', name='Light Healing Potion', color=libtcod.red, item=Item( use_function='cast_heal( "Potion", player.fighter.max_hp/6, player)' ) ),
                  Object( x=0, y=0, char='$', name='Scroll of Chain Lightning', color=libtcod.yellow, item=Item(use_function='cast_lightning( player, damage=20, sRange=5, chainLength=3 )') )
              ]
              for item in monster.inventory:
                  if item.equipment:
                      item.equipment.equip()
  </code></pre>
  
  <p>then I am trying to make it drop all of its items in this function.</p>
  
  <pre><code>def monster_death(monster): #consider letting a monster keep it's char but change the bg and the char to red.
      #transform it into a nasty corpse! it doesn't block, can't be
      #attacked and doesn't move
      message( monster.name.capitalize() + ' is dead!', libtcod.orange)
      monster.char = '%'
      monster.color = libtcod.dark_red
      monster.blocks = False
      monster.fighter = None
      monster.ai = None
      monster.name = 'remains of ' + monster.name
      monster.draw_last()
      for element in monster.inventory:
          if element.item:
              element.item.drop()
  </code></pre>
  
  <p>What is happening is; it is iterating over all but one of the items in the inventory list but not the entire list. (I know from debugging one of the items stays in the inventory list and doesn't drop)</p>
  
  <p>also; here is the drop function in the item class if this helps.</p>
  
  <pre><code>def drop(self):
          for object in objects:
              if self.owner in object.inventory:
                  if self.owner.equipment:
                      self.owner.equipment.dequip()
                  #add to the map and remove from the player's inventory. also, place it at the player's coordinates
                  objects.append(self.owner)
                  object.inventory.remove(self.owner)
                  self.owner.x = object.x
                  self.owner.y = object.y
                  if object == player:
                      message('You dropped a ' + self.owner.name + '.', libtcod.yellow)
  </code></pre>
  
  <p>I am having really hard time trying to crush this bug...any help is appreciated. :)</p>