title: printing out python list from python binary tree
body: <p>I want to define a function which returns a list of the tree node values. The list is in level order (top to bottom, left to right), if a
  child is missing then in its location, "None" is inserted. </p>
  
  <p>This is the Binary Tree implementation</p>
  
  <pre><code>class BinaryTree:
  
  def __init__(self, data, left = None, right = None):
  
      self.left = left
      self.right  = right
  
  def insert_left(self, data):
      self.left = BinaryTree(data, left=self.left)  
  
  def insert_right(self, data):
      self.right = BinaryTree(data, right=self.right)
  
  def set_value(self, val):
      self.key = val
  
  def get_value(self):
      return self.key
  
  def create_string(self, indent):
      string = str(self.key) + '---+'
      if self.left:
          string += '\n(l)' + indent + self.left.create_string(indent + '    ')
      if self.right:
          string += '\n(r)' + indent + self.right.create_string(indent + '    ')
      return string
  
  def __str__(self):
      return self.create_string('  ')
  
  def return_list(self, templist):
      templist.append(self.key)
      if self.left is None:
          templist.append(None)
      else:
          self.left.return_list(templist)
      if self.right is None:
          templist.append(None)
      else:
          self.right.return_list(templist)
  
  def main():    
      tree = BinaryTree(3) 
      tree.insert_left(29)
      tree.insert_right(4)
      right = tree.get_right_subtree()
      left = tree.get_left_subtree()
      left.insert_left(26)
      right.insert_right(2)
      right2 = right.get_right_subtree()
      right2.insert_left(9)
      templist = []
      tree.return_list(templist)
  main()       
  </code></pre>