Skip to content

Instantly share code, notes, and snippets.

@davisvictorns
Created September 15, 2021 01:32
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 davisvictorns/88e061d8b3246670f445f89187f10c3f to your computer and use it in GitHub Desktop.
Save davisvictorns/88e061d8b3246670f445f89187f10c3f to your computer and use it in GitHub Desktop.
edg_copy = edges.copy()
edge_with_weight = []
while len(edg_copy) > 0:
curr_edge = edg_copy[0]
equivalent_edges = []
# get the equivalent edges
# ('a', 'b') is equivalent to ('b', 'a') because it's not a directed connection
for edge in edg_copy:
is_different = False
for hashtag in edge:
if hashtag not in curr_edge:
is_different = True
if (not is_different):
equivalent_edges.append(edge)
weight = len(equivalent_edges)
edge_with_weight.append(curr_edge + (weight,))
for edge in equivalent_edges:
edg_copy.remove(edge)
print(edge_with_weight)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment