code: def create_hc(G):
      """Creates hierarchical cluster of graph G from distance matrix"""
      path_length = nx.all_pairs_shortest_path_length(G)
      distances = np.zeros((len(G), len(G)))
      for u, p in path_length:
          for v, d in p.items():
              distances[u][v] = d
      # Create hierarchical cluster
      Y = distance.squareform(distances)
      Z = hierarchy.complete(
          Y
      )  # Creates HC using farthest point linkage
      # This partition selection is arbitrary, for illustrative purposes
      membership = list(hierarchy.fcluster(Z, t=1.15))
      # Create collection of lists for blockmodel
      partition = defaultdict(list)
      for n, p in zip(list(range(len(G))), membership):
          partition[p].append(n)
      return list(partition.values())
  
imports: from collections import defaultdict
  import matplotlib.pyplot
  import networkx
  import numpy
  from scipy.cluster import hierarchy
  from scipy.spatial import distance
label_desc: Use image node_id 1 for calling a global function with example usage: create_hc(G) and returns: list