def make_link(G, node1, node2): if node1 not in G: G[node1] = {} (G[node1])[node2] = 1 if node2 not in G: G[node2] = {} (G[node2])[node1] = 1 return G flights = [("ORD", "SEA"), ("ORD", "LAX"), ('ORD', 'DFW'), ('ORD', 'PIT'), ('SEA', 'LAX'), ('LAX', 'DFW'), ('ATL', 'PIT'), ('ATL', 'RDU'), ('RDU', 'PHL'), ('PIT', 'PHL'), ('PHL', 'PVD')] G = {} for (x,y) in flights: make_link(G,x,y) def clustering_coefficient(G,v): pass total = 0 for v in G.keys(): total += clustering_coefficient(G,v) print total/len(G)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question