nodes: 0, module; 1, function_definition; 2, function_name:convert_node_labels_to_integers; 3, parameters; 4, block; 5, identifier:G; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, expression_statement; 14, comment:# create node attribute with the old label; 15, if_statement; 16, return_statement; 17, identifier:first_label; 18, integer:0; 19, identifier:ordering; 20, string:"default"; 21, identifier:label_attribute; 22, None; 23, comment:"""Return a copy of the graph G with the nodes relabeled with integers.
  
      Parameters
      ----------
      G : graph
         A NetworkX graph
  
      first_label : int, optional (default=0)
         An integer specifying the offset in numbering nodes.
         The n new integer labels are numbered first_label, ..., n-1+first_label.
  
      ordering : string
         "default" : inherit node ordering from G.nodes()
         "sorted"  : inherit node ordering from sorted(G.nodes())
         "increasing degree" : nodes are sorted by increasing degree
         "decreasing degree" : nodes are sorted by decreasing degree
  
      label_attribute : string, optional (default=None)
         Name of node attribute to store old label.  If None no attribute
         is created.
  
      Notes
      -----
      Node and edge attribute data are copied to the new (relabeled) graph.
  
      See Also
      --------
      relabel_nodes
      """; 24, assignment; 25, comparison_operator:ordering == "default"; 26, block; 27, elif_clause; 28, elif_clause; 29, elif_clause; 30, else_clause; 31, assignment; 32, assignment; 33, comparison_operator:label_attribute is not None; 34, block; 35, identifier:H; 36, identifier:N; 37, binary_operator:G.number_of_nodes() + first_label; 38, identifier:ordering; 39, string:"default"; 40, expression_statement; 41, comparison_operator:ordering == "sorted"; 42, block; 43, comparison_operator:ordering == "increasing degree"; 44, block; 45, comparison_operator:ordering == "decreasing degree"; 46, block; 47, block; 48, identifier:H; 49, call; 50, attribute; 51, binary_operator:"(" + G.name + ")_with_int_labels"; 52, identifier:label_attribute; 53, None; 54, expression_statement; 55, call; 56, identifier:first_label; 57, assignment; 58, identifier:ordering; 59, string:"sorted"; 60, expression_statement; 61, expression_statement; 62, expression_statement; 63, identifier:ordering; 64, string:"increasing degree"; 65, expression_statement; 66, expression_statement; 67, comment:# in-place sort from lowest to highest degree; 68, expression_statement; 69, identifier:ordering; 70, string:"decreasing degree"; 71, expression_statement; 72, expression_statement; 73, comment:# in-place sort from lowest to highest degree; 74, expression_statement; 75, expression_statement; 76, raise_statement; 77, identifier:relabel_nodes; 78, argument_list; 79, identifier:H; 80, identifier:name; 81, binary_operator:"(" + G.name; 82, string:")_with_int_labels"; 83, call; 84, attribute; 85, argument_list; 86, identifier:mapping; 87, call; 88, assignment; 89, call; 90, assignment; 91, assignment; 92, call; 93, assignment; 94, assignment; 95, call; 96, call; 97, assignment; 98, call; 99, identifier:G; 100, identifier:mapping; 101, string:"("; 102, attribute; 103, attribute; 104, argument_list; 105, identifier:G; 106, identifier:number_of_nodes; 107, identifier:dict; 108, argument_list; 109, identifier:nlist; 110, call; 111, attribute; 112, argument_list; 113, identifier:mapping; 114, call; 115, identifier:dv_pairs; 116, list_comprehension; 117, attribute; 118, argument_list; 119, identifier:mapping; 120, call; 121, identifier:dv_pairs; 122, list_comprehension; 123, attribute; 124, argument_list; 125, attribute; 126, argument_list; 127, identifier:mapping; 128, call; 129, attribute; 130, argument_list; 131, identifier:G; 132, identifier:name; 133, identifier:nx; 134, identifier:set_node_attributes; 135, identifier:H; 136, identifier:label_attribute; 137, call; 138, call; 139, attribute; 140, argument_list; 141, identifier:nlist; 142, identifier:sort; 143, identifier:dict; 144, argument_list; 145, tuple; 146, for_in_clause; 147, identifier:dv_pairs; 148, identifier:sort; 149, identifier:dict; 150, argument_list; 151, tuple; 152, for_in_clause; 153, identifier:dv_pairs; 154, identifier:sort; 155, identifier:dv_pairs; 156, identifier:reverse; 157, identifier:dict; 158, argument_list; 159, identifier:nx; 160, identifier:NetworkXError; 161, call; 162, identifier:dict; 163, generator_expression; 164, identifier:zip; 165, argument_list; 166, identifier:G; 167, identifier:nodes; 168, call; 169, identifier:d; 170, identifier:n; 171, tuple_pattern; 172, call; 173, call; 174, identifier:d; 175, identifier:n; 176, tuple_pattern; 177, call; 178, call; 179, attribute; 180, argument_list; 181, tuple; 182, for_in_clause; 183, call; 184, call; 185, identifier:zip; 186, argument_list; 187, identifier:n; 188, identifier:d; 189, attribute; 190, argument_list; 191, identifier:zip; 192, argument_list; 193, identifier:n; 194, identifier:d; 195, attribute; 196, argument_list; 197, identifier:zip; 198, argument_list; 199, string; 200, identifier:format; 201, identifier:ordering; 202, identifier:v; 203, identifier:k; 204, pattern_list; 205, call; 206, attribute; 207, argument_list; 208, identifier:range; 209, argument_list; 210, identifier:nlist; 211, call; 212, identifier:G; 213, identifier:degree_iter; 214, list_comprehension; 215, call; 216, identifier:G; 217, identifier:degree_iter; 218, list_comprehension; 219, call; 220, string_content:Unknown node ordering: {0}; 221, identifier:k; 222, identifier:v; 223, attribute; 224, argument_list; 225, identifier:G; 226, identifier:nodes; 227, identifier:first_label; 228, identifier:N; 229, identifier:range; 230, argument_list; 231, identifier:n; 232, for_in_clause; 233, identifier:range; 234, argument_list; 235, identifier:n; 236, for_in_clause; 237, identifier:range; 238, argument_list; 239, identifier:mapping; 240, identifier:items; 241, identifier:first_label; 242, identifier:N; 243, pattern_list; 244, identifier:dv_pairs; 245, identifier:first_label; 246, identifier:N; 247, pattern_list; 248, identifier:dv_pairs; 249, identifier:first_label; 250, identifier:N; 251, identifier:d; 252, identifier:n; 253, identifier:d; 254, identifier:n
code: def convert_node_labels_to_integers(G, first_label=0, ordering="default",
                                      label_attribute=None):
      """Return a copy of the graph G with the nodes relabeled with integers.
  
      Parameters
      ----------
      G : graph
         A NetworkX graph
  
      first_label : int, optional (default=0)
         An integer specifying the offset in numbering nodes.
         The n new integer labels are numbered first_label, ..., n-1+first_label.
  
      ordering : string
         "default" : inherit node ordering from G.nodes()
         "sorted"  : inherit node ordering from sorted(G.nodes())
         "increasing degree" : nodes are sorted by increasing degree
         "decreasing degree" : nodes are sorted by decreasing degree
  
      label_attribute : string, optional (default=None)
         Name of node attribute to store old label.  If None no attribute
         is created.
  
      Notes
      -----
      Node and edge attribute data are copied to the new (relabeled) graph.
  
      See Also
      --------
      relabel_nodes
      """
      N = G.number_of_nodes() + first_label
      if ordering == "default":
          mapping = dict(zip(G.nodes(), range(first_label, N)))
      elif ordering == "sorted":
          nlist = G.nodes()
          nlist.sort()
          mapping = dict(zip(nlist, range(first_label, N)))
      elif ordering == "increasing degree":
          dv_pairs = [(d, n) for (n, d) in G.degree_iter()]
          dv_pairs.sort()  # in-place sort from lowest to highest degree
          mapping = dict(zip([n for d, n in dv_pairs], range(first_label, N)))
      elif ordering == "decreasing degree":
          dv_pairs = [(d, n) for (n, d) in G.degree_iter()]
          dv_pairs.sort()  # in-place sort from lowest to highest degree
          dv_pairs.reverse()
          mapping = dict(zip([n for d, n in dv_pairs], range(first_label, N)))
      else:
          raise nx.NetworkXError('Unknown node ordering: {0}'.format(ordering))
      H = relabel_nodes(G, mapping)
      H.name = "(" + G.name + ")_with_int_labels"
      # create node attribute with the old label
      if label_attribute is not None:
          nx.set_node_attributes(H, label_attribute,
                                 dict((v, k) for k, v in mapping.items()))
      return H