nodes: 0, module; 1, function_definition; 2, function_name:relabel_nodes; 3, parameters; 4, block; 5, identifier:G; 6, identifier:mapping; 7, default_parameter; 8, expression_statement; 9, comment:# you can pass a function f(old_label)->new_label; 10, comment:# but we'll just make a dictionary here regardless; 11, if_statement; 12, if_statement; 13, identifier:copy; 14, True; 15, comment:"""Relabel the nodes of the graph G.
  
      Parameters
      ----------
      G : graph
         A NetworkX graph
  
      mapping : dictionary
         A dictionary with the old labels as keys and new labels as values.
         A partial mapping is allowed.
  
      copy : bool (optional, default=True)
         If True return a copy, or if False relabel the nodes in place.
  
      Examples
      --------
      >>> G=nx.path_graph(3)  # nodes 0-1-2
      >>> mapping={0:'a',1:'b',2:'c'}
      >>> H=nx.relabel_nodes(G,mapping)
      >>> print(sorted(H.nodes()))
      ['a', 'b', 'c']
  
      >>> G=nx.path_graph(26) # nodes 0..25
      >>> mapping=dict(zip(G.nodes(),"abcdefghijklmnopqrstuvwxyz"))
      >>> H=nx.relabel_nodes(G,mapping) # nodes a..z
      >>> mapping=dict(zip(G.nodes(),range(1,27)))
      >>> G1=nx.relabel_nodes(G,mapping) # nodes 1..26
  
      Partial in-place mapping:
  
      >>> G=nx.path_graph(3)  # nodes 0-1-2
      >>> mapping={0:'a',1:'b'} # 0->'a' and 1->'b'
      >>> G=nx.relabel_nodes(G,mapping, copy=False)
  
      print(G.nodes())
      [2, 'b', 'a']
  
      Mapping as function:
  
      >>> G=nx.path_graph(3)
      >>> def mapping(x):
      ...    return x**2
      >>> H=nx.relabel_nodes(G,mapping)
      >>> print(H.nodes())
      [0, 1, 4]
  
      Notes
      -----
      Only the nodes specified in the mapping will be relabeled.
  
      The keyword setting copy=False modifies the graph in place.
      This is not always possible if the mapping is circular.
      In that case use copy=True.
  
      See Also
      --------
      convert_node_labels_to_integers
      """; 16, not_operator; 17, block; 18, else_clause; 19, identifier:copy; 20, block; 21, else_clause; 22, call; 23, expression_statement; 24, block; 25, return_statement; 26, block; 27, identifier:hasattr; 28, argument_list; 29, assignment; 30, expression_statement; 31, call; 32, return_statement; 33, identifier:mapping; 34, string:"__getitem__"; 35, identifier:m; 36, call; 37, assignment; 38, identifier:_relabel_copy; 39, argument_list; 40, call; 41, identifier:dict; 42, generator_expression; 43, identifier:m; 44, identifier:mapping; 45, identifier:G; 46, identifier:m; 47, identifier:_relabel_inplace; 48, argument_list; 49, tuple; 50, for_in_clause; 51, identifier:G; 52, identifier:m; 53, identifier:n; 54, call; 55, identifier:n; 56, identifier:G; 57, identifier:mapping; 58, argument_list; 59, identifier:n
code: def relabel_nodes(G, mapping, copy=True):
      """Relabel the nodes of the graph G.
  
      Parameters
      ----------
      G : graph
         A NetworkX graph
  
      mapping : dictionary
         A dictionary with the old labels as keys and new labels as values.
         A partial mapping is allowed.
  
      copy : bool (optional, default=True)
         If True return a copy, or if False relabel the nodes in place.
  
      Examples
      --------
      >>> G=nx.path_graph(3)  # nodes 0-1-2
      >>> mapping={0:'a',1:'b',2:'c'}
      >>> H=nx.relabel_nodes(G,mapping)
      >>> print(sorted(H.nodes()))
      ['a', 'b', 'c']
  
      >>> G=nx.path_graph(26) # nodes 0..25
      >>> mapping=dict(zip(G.nodes(),"abcdefghijklmnopqrstuvwxyz"))
      >>> H=nx.relabel_nodes(G,mapping) # nodes a..z
      >>> mapping=dict(zip(G.nodes(),range(1,27)))
      >>> G1=nx.relabel_nodes(G,mapping) # nodes 1..26
  
      Partial in-place mapping:
  
      >>> G=nx.path_graph(3)  # nodes 0-1-2
      >>> mapping={0:'a',1:'b'} # 0->'a' and 1->'b'
      >>> G=nx.relabel_nodes(G,mapping, copy=False)
  
      print(G.nodes())
      [2, 'b', 'a']
  
      Mapping as function:
  
      >>> G=nx.path_graph(3)
      >>> def mapping(x):
      ...    return x**2
      >>> H=nx.relabel_nodes(G,mapping)
      >>> print(H.nodes())
      [0, 1, 4]
  
      Notes
      -----
      Only the nodes specified in the mapping will be relabeled.
  
      The keyword setting copy=False modifies the graph in place.
      This is not always possible if the mapping is circular.
      In that case use copy=True.
  
      See Also
      --------
      convert_node_labels_to_integers
      """
      # you can pass a function f(old_label)->new_label
      # but we'll just make a dictionary here regardless
      if not hasattr(mapping, "__getitem__"):
          m = dict((n, mapping(n)) for n in G)
      else:
          m = mapping
      if copy:
          return _relabel_copy(G, m)
      else:
          return _relabel_inplace(G, m)