title: Convert binary tree to a list with level order in Python
body: <p>I have not found any related questions yet.</p>
  <p>So the problem is: given an incomplete binary tree, say the root of the tree, how can I convert it into a list in level order in Python such that the empty nodes (missing nodes in that level) are represented as &quot;None&quot; in the list.</p>
  <p>For example, I have this tree:</p>
  <pre><code>     1
     /   \
   4      0.52
  / \      / \
     2.5
  </code></pre>
  <p>I want to get the following list:</p>
  <pre><code>[1, 4, 0.52, None, 2.5, None, None]
  </code></pre>
  <p>by using some function like:</p>
  <pre><code>list = toList(root)
  </code></pre>
  <p>In addition, I have tree structured like this:</p>
  <pre><code>class TreeNode:
  
  def __init__(self, value, isLeaf):
  
      self.left = None
      self.right = None
      self.value = value
      self.isLeaf = isLeaf
  </code></pre>
  <p>And borrow the solution from another post (to a list without 'None' taken place):</p>
  <pre><code>def toList(root):
      node_list = []
      thislevel = [root]
      while thislevel:
          nextlevel = list()
          
          for n in thislevel:
              # print(n.value)
              node_list.append(n.value)
  
              if n.left: 
                  nextlevel.append(n.left)
              if n.right: 
                  nextlevel.append(n.right)
          # print
          thislevel = nextlevel
      return node_list
  
  my_list = toList(root)
  print(my_list)
  </code></pre>
  <p>This gives the following so far:</p>
  <pre><code>[1, 4, 0.52, 2.5]
  </code></pre>
  <p>I am stuck here, don't know how to properly insert 'None' into the list...</p>
  <p>Thanks!</p>