title: How to calculate clustering coefficient of each node in the graph in Python using Networkx
body: <p>I want to calculate the clustering coefficient of each node in the graph using python and Networkx functions. I know there might be a built-in function for this purpose but I want to calculate it by myself but my code is not working. Can someone please point out error? </p>
  
  <p>I have tried to test and debug the code. No. of neighbors of each node i.e. n_neighbors are calculated seem to be ok but next code is somehow not running or have some error in it which I'm unable to detect.</p>
  
  <pre><code>import matplotlib as mpl
  import matplotlib.pyplot as plt
  import numpy as np
  
  for node in network.nodes():
      neighbours=nx.neighbors(network,node)
      count=0
      for n in neighbours:
          count+=1
      n_neighbors=count
      n_links=0
      if n_neighbors&gt;1:
          for node1 in neighbours:
              for node2 in neighbours:
                  if nx.has_edge(node1,node2):
                      n_links+=1
                      n_links/+2 #because n_links is calculated twice
          clustering_coefficient=n_links/(0.5*n_neighbors*(n_neighbors-1))
          print(clustering_coefficient)
      else:
          print(0)
  </code></pre>