import networkx as nx


class ConnectedComponents:
    def __init__(self, g):
        self.g = g

    def get_connected_components(self):
        clusters = []
        for components in nx.connected_components(self.g):
            clusters.append(components)

        cluster_id = 0
        for cluster in clusters:
            for node in cluster:
                self.g[node]['cluster'] = cluster_id
            cluster_id += 1

        return clusters

import networkx as nx


class ConnectedComponents:
    def __init__(self, g):
        self.g = g

    def get_clusters(self):
        clusters = []
        for components in nx.connected_components(self.g):
            clusters.append(components)

        cluster_id = 0
        for cluster in clusters:
            for node in cluster:
                self.g.node[node]['cluster'] = cluster_id
            cluster_id += 1

        return clusters

Rename method get_cluster and revise self.g.node when accessing a node
Rename method get_cluster and revise self.g.node when accessing a node

  import networkx as nx
  
  
  class ConnectedComponents:
      def __init__(self, g):
          self.g = g
  
-     def get_connected_components(self):
+     def get_clusters(self):
          clusters = []
          for components in nx.connected_components(self.g):
              clusters.append(components)
  
          cluster_id = 0
          for cluster in clusters:
              for node in cluster:
-                 self.g[node]['cluster'] = cluster_id
+                 self.g.node[node]['cluster'] = cluster_id
              cluster_id += 1
  
          return clusters
  
Rename method get_cluster and revise self.g.node when accessing a node
## Code Before:
import networkx as nx


class ConnectedComponents:
    def __init__(self, g):
        self.g = g

    def get_connected_components(self):
        clusters = []
        for components in nx.connected_components(self.g):
            clusters.append(components)

        cluster_id = 0
        for cluster in clusters:
            for node in cluster:
                self.g[node]['cluster'] = cluster_id
            cluster_id += 1

        return clusters

## Instruction:
Rename method get_cluster and revise self.g.node when accessing a node
## Code After:
import networkx as nx


class ConnectedComponents:
    def __init__(self, g):
        self.g = g

    def get_clusters(self):
        clusters = []
        for components in nx.connected_components(self.g):
            clusters.append(components)

        cluster_id = 0
        for cluster in clusters:
            for node in cluster:
                self.g.node[node]['cluster'] = cluster_id
            cluster_id += 1

        return clusters
