code: def _remove_nonterminal_leaves(G, terminals):
      terminals_set = set(terminals)
      for n in list(G.nodes):
          if n not in terminals_set and G.degree(n) == 1:
              G.remove_node(n)
  
file_path: networkx/networkx/algorithms/approximation/steinertree.py
imports: from itertools import chain
  import networkx
  from networkx.utils import not_implemented_for, pairwise
label_desc: Use image node_id 4 for calling a global function with example usage: _remove_nonterminal_leaves(G, terminals) without return types