Skip to content

Instantly share code, notes, and snippets.

@timothyrenner
Created September 13, 2018 15:39
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 timothyrenner/8447c9f6862b0443dd6417323deb009d to your computer and use it in GitHub Desktop.
Save timothyrenner/8447c9f6862b0443dd6417323deb009d to your computer and use it in GitHub Desktop.
Average Agreement, Attempt 3
def average_agreement(list1, list2, max_depth):
# Empty lists evaluate to false.
if (not list1) or (not list2):
return 0.0
### NEW CODE ###
# Truncate the depth
max_list_len = max(len(list1), len(list2))
max_depth = min(max_depth, max_list_len)
agreements = []
for depth in range(1, max_depth+1):
set1 = set(list1[:depth])
set2 = set(list2[:depth])
intersection = set1 & set2
agreements.append(2 * len(intersection) / (len(set1) + len(set2)))
return sum(agreements) / len(agreements)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment