class_docstr: A data structure to represent a parse tree
class_docstr_tok: ["A","data","structure","to","represent","a","parse","tree"]
docstr: Replace all leaf words with the words in the given list (or iterable)
  
  Returns a new tree
docstr_tok: ["Replace","all","leaf","words","with","the","words","in","the","given","list","(","or","iterable",")","Returns","a","new","tree"]
code: def replace_words(self, words):
      """
      Replace all leaf words with the words in the given list (or iterable)
  
      Returns a new tree
      """
      word_iterator = iter(words)
  
      def recursive_replace_words(subtree):
          if subtree.is_leaf():
              word = next(word_iterator, None)
              if word is None:
                  raise ValueError(
                      "Not enough words to replace all leaves"
                  )
              return Tree(word)
          return Tree(
              subtree.label,
              [recursive_replace_words(x) for x in subtree.children],
          )
  
      new_tree = recursive_replace_words(self)
      if any(True for _ in word_iterator):
          raise ValueError("Too many words for the given tree")
      return new_tree
  
imports: from collections import deque, Counter
  from enum import Enum
  from io import StringIO
  import itertools
  import re
  import warnings
  from stanza.models.common.stanza_object import StanzaObject
label_desc: Use image node_id 26 for calling the Tree obj's underlying member method code with example usage: obj.replace_words(words) and returns: new_tree, Tree, Tree