code: def replace(text, replacements):
      # type: (str, List[Tuple[int, int, str]]) -> str
      """
      Replaces multiple slices of text with new values. This is a convenience method for making code
      modifications of ranges e.g. as identified by ``ASTTokens.get_text_range(node)``. Replacements is
      an iterable of ``(start, end, new_text)`` tuples.
  
      For example, ``replace("this is a test", [(0, 4, "X"), (8, 9, "THE")])`` produces
      ``"X is THE test"``.
      """
      p = 0
      parts = []
      for start, end, new_text in sorted(replacements):
          parts.append(text[p:start])
          parts.append(new_text)
          p = end
      parts.append(text[p:])
      return "".join(parts)
  
imports: import ast
  import collections
  import io
  import sys
  import token
  import tokenize
  from abc import ABCMeta
  from ast import Module, expr, AST
  from typing import Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Union, cast, Any, TYPE_CHECKING
  from six import iteritems
label_desc: Use image node_id 17 for calling a global function with example usage: replace(text, replacements) and returns: str