parameters: (self, root)
return_statement: return '[%s]' % (','.join(nodes))
docstring: Encodes a tree to a single string.
          
          :type root: TreeNode
          :rtype: str
docstring_summary: Encodes a tree to a single string.
          
          :type root: TreeNode
          :rtype: str
docstring_tokens: Encodes a tree to a single string . : type root : TreeNode : rtype : str
function: def serialize(self, root):
          """Encodes a tree to a single string.
          
          :type root: TreeNode
          :rtype: str
          """
          if root is None:
              return '[]'
          
          queue = [root]
          index = 0
          while index < len(queue):
              node = queue[index]
              if node is not None:
                  queue.append(node.left)
                  queue.append(node.right)
              index += 1
                  
          while (len(queue) > 0 and queue[-1] is None):
              queue.pop()
          
          nodes = ['#' if n is None else str(n.val) for n in queue]
          
          return '[%s]' % (','.join(nodes))
function_tokens: def serialize ( self , root ) : if root is None : return '[]' queue = [ root ] index = 0 while index < len ( queue ) : node = queue [ index ] if node is not None : queue . append ( node . left ) queue . append ( node . right ) index += 1 while ( len ( queue ) > 0 and queue [ - 1 ] is None ) : queue . pop ( ) nodes = [ '#' if n is None else str ( n . val ) for n in queue ] return '[%s]' % ( ',' . join ( nodes ) )