Skip to content

Instantly share code, notes, and snippets.

@bigsnarfdude
Last active November 26, 2021 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigsnarfdude/f4af3a330286871c82e8ee2bf7bbf93c to your computer and use it in GitHub Desktop.
Save bigsnarfdude/f4af3a330286871c82e8ee2bf7bbf93c to your computer and use it in GitHub Desktop.
import networkx as nx
B = nx.Graph()
# Add nodes with the node attribute "bipartite"
B.add_nodes_from([1, 2, 3, 4], bipartite=0)
B.add_nodes_from(["a", "b", "c"], bipartite=1)
# Add edges only between nodes of opposite node sets
B.add_edges_from([(1, "a"), (1, "b"), (2, "b"), (2, "c"), (3, "c"), (4, "a")])
def get_webpage_visitors(webpage, target_graph):
for page in target_graph.adjacency():
if page[0] == webpage:
return list(page[1].keys())
else:
return None
get_webpage_visitors(1, B)
def get_webpage_count(webpage, target_graph):
for page in target_graph.adjacency():
if page[0] == webpage:
return len(page[1].keys())
else:
return None
get_webpage_count(1, B)
def get_visitor_list(visitor, target_graph):
for page in target_graph.adjacency():
if page[0] == visitor:
return list(page[1].keys())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment