title: Python dicts in objects behaviour?
body: <p>I'm trying to make a node class with a name and a dict of its neighbors, along with the tag by which it refers to this neighbor (not necessarily the neighbor's name). </p>
  
  <pre><code>class node:
  def __init__(self,name='',neighbors={}):
      self.name=name
      self.neighbors=neighbors
  
  def addNeighbor(self,neighborTag,neighbor):
      if neighborTag not in self.neighbors.keys():
          self.neighbors[neighborTag] = neighbor
  </code></pre>
  
  <p>However when I perform the following:</p>
  
  <pre><code>foo = node(name='foo')
  foo.addNeighbor('fooneighbor',node(name='bar'))
  </code></pre>
  
  <p>The dict entry {'fooneighbor',<em>node object</em>} also appears in foo.neighbors['fooneighbor'].neighbors (which I expected to be blank).</p>
  
  <p>I'm guessing this is something to do with how dicts work that I'm not aware of. Can anyone enlighten me?</p>