code: def relabel_nodes(G, mapping, copy=True):
      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)