Created
September 13, 2018 15:39
-
-
Save timothyrenner/8447c9f6862b0443dd6417323deb009d to your computer and use it in GitHub Desktop.
Average Agreement, Attempt 3
This file contains hidden or 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
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