Last active
November 26, 2021 16:13
-
-
Save bigsnarfdude/f4af3a330286871c82e8ee2bf7bbf93c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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