title: check existing values in binary tree python
body: <p>Have some errors and been stuck on this problem for awhile. I read words from a file like this below but the problem is with the if statements. it doesn't print an existing value it just keeps printing all values to the screen. I am using python 3.3.. If you check the file the only value it would print is via and not add it again to the tree.</p>
  
  <p>Textfile - <code>words.txt</code></p>
  
  <pre><code>nia
  ria
  via
  sia
  via
  </code></pre>
  
  <p>Code</p>
  
  <pre><code>class Bintree:
      def __init__(self, data):
          self.left = None 
          self.right = None 
          self.data = data 
  
      def put(self, data):
          if data &lt; self.data:
              if self.left is None:
                  self.left = Bintree(data)
              else:
                  self.left.put(data)
          else:
              if self.right is None:
                  self.right = Bintree(data)
              else:
                  self.right.put(data)
  
      def write(self):  
          if self.left: 
              self.left.write()
          print(self.data) 
          if self.right: 
              self.right.write()
  
      def exists(self, data):
          if data &lt; self.data:
              if self.left is None:
                  return None, None
              return self.left.exists(data, self)
          elif data &gt; self.data:
              if self.right is None:
                  return None, None
              return self.right.exists(data, self)
          else:
              return self.data
  
  
  root = Bintree("root")
  with open("words.txt", "r", encoding = "utf-8") as file:
      for row in file:
          word = row.strip()
          checklist = root.exists(word)
          if checklist == word:
              print(word, end = " ")
          else:
              root.put(word)
  print("\n")
  </code></pre>