-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
def frequency_comparison(table1, table2):
mutual_appearances = []
appearances = []
for key in table1.keys(): #we search if the keys of table 1 are in table 2
if key in table2.keys():
if table1[key]<table2[key]: #if the value of the key in table 1 is smaller than the value in table 2 we save it in mutual_appearances
mutual_appearances.append(table1[key])
appearances.append(table2[key])
else: #otherwise we save it in appareances and the value of the table 2 is going to mutual_appearances
mutual_appearances.append(table2[key])
appearances.append(table1[key])
else: #if the value isn't in the table 2 we add it in appearances as well
appearances.append(table1[key])
for key in table2.keys():
if key not in table1.keys(): #we add to appearances the values of table 2 that not appear in table 1
appearances.append(table2[key])
return len(mutual_appearances)/len(appearances)
Really close on this function! We just need to change one thing: use the sum() function instead of the len() function to perform the final calculation. Notably, the sum() function is used to calculate the summation of all items in a list. So, if we call sum([1, 2, 3]) then the function will return 6. Notably, if we call len() on this same list, it will only return 3.
So, in this function, we need to use sum() instead of len() to calculate the frequency:
return sum(mutual_appearances) / sum(appearances)
This will now accurately calculate the frequency comparison. So, very close! Just one small change and it was 100% correct.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels