title: Python loop appending same object twice
body: <p>I'm following the YouTube video <a href="https://www.youtube.com/watch?v=RrPZza_vZ3w" rel="nofollow">Learn Python through Data Hacking</a> and am expanding on the sort of "legacy" inline way by adding classes to learn all the ins and outs of Python OOP.  Basically the guy in the video has you grab the Chicago bus line's route, parse it, and find which bus his friend left his suitcase on by comparing lat, long, time, distace, etc.</p>
  
  <p>The XML file I'm working with has a bunch of values like so:</p>
  
  <pre><code>&lt;bus&gt;
      &lt;id&gt;1867&lt;/id&gt;
      &lt;rt&gt;22&lt;/rt&gt;
  
      &lt;d&gt;North Bound&lt;/d&gt;
      &lt;dd&gt;Northbound&lt;/dd&gt;
      &lt;dn&gt;N&lt;/dn&gt;
      &lt;lat&gt;41.89167051315307&lt;/lat&gt;
      &lt;lon&gt;-87.6297836303711&lt;/lon&gt;
      &lt;pid&gt;5421&lt;/pid&gt;
      &lt;pd&gt;Northbound&lt;/pd&gt;
      &lt;run&gt;P258&lt;/run&gt;
      &lt;fs&gt;Howard&lt;/fs&gt;
      &lt;op&gt;30090&lt;/op&gt;
      &lt;dip&gt;8858&lt;/dip&gt;
      &lt;bid&gt;7323012&lt;/bid&gt;
      &lt;wid1&gt;0P&lt;/wid1&gt;
      &lt;wid2&gt;258&lt;/wid2&gt;                
  &lt;/bus&gt;
  </code></pre>
  
  <p>From there, I need to find which bus' latitude are north from his position (defined in the class, moot for this example). From those nodes, I'm creating a <code>Bus</code> object like so:</p>
  
  <pre><code>class Bus:
      # The original XML node
      __xml = None
  
      # Our dictionary for properties to shadow a get() function on this object
      __tree = {}
  
      def __init__(self, busxml):
          self.__xml = busxml
          for e in busxml:
              self.__tree[e.tag] = busxml.findtext(e.tag)
  
      def gettree(self):
          return self.__tree
  
      # Tries to return prop, or returns None
      def get(self, prop):
          try:
              return self.__tree[prop]
          except KeyError:
              return -1
      def getall(self):
          return self.__tree
  </code></pre>
  
  <p>From the "main" file, I'm looping through the values and appending matches based on the <code>lat</code> node's text value:</p>
  
  <pre><code># __getRouteData() is the url open and write function, works fine.
  # parser is the xml.etree.ElementTree parse class
  if self.__getRouteData() == True:
      xmlParser = parser(self.__xmlFile)
      busses = xmlParser.getnodes()
  
      matches = []
      # loop over all
      for busTree in busses:
          bus = Bus(busTree)
  
          if float(bus.get('lat')) &gt; self.__lat:
              matches.append(bus)
              print 'appending', bus.get('id')
  
      for bus in matches:
          print bus.get('id')
  </code></pre>
  
  <p>The snag I'm hitting is in the second <code>for</code> loop above.  In the first loop, the output is telling me things are working well.  The second one outputs the same value twice.  It reminds me of the behavior with Javascript <code>for()</code> loops where, without a closure, only the last value is acted upon.  My output from the console is as follows:</p>
  
  <pre><code>appending 1784
  appending 4057
  4057
  4057
  </code></pre>
  
  <p>See... it's telling me it's appending unique busses to my <code>matches</code> list, but when I iterate over the <code>matches</code> list, its only giving me one bus.</p>
  
  <p>Another snippet that tells me something's funky with the second loop:</p>
  
  <pre><code>print 'Matches', matches
      for bus in matches:
          print bus.get('id')
          # Matches [&lt;busutils.Bus instance at 0xb6f92b8c&gt;, &lt;busutils.Bus instance at 0xb6f92d0c&gt;]
          # 4057
          # 4057
  </code></pre>
  
  <p>The output of the list is showing me different hashes (...right?) of the objects in the list, hence saying they're two different objects, and thus have different data, but the loop isn't playing nicely.</p>
  
  <p>Obviously I'm just getting into python, but have experience in Java, Javascript, PHP, etc, so I'm not sure what I'm missing in these simple loops.</p>
  
  <p>Thanks!</p>