I'm having trouble indexing a result in a list.
The function "Similar" calculates the similarity between two strings in a range from 0 to 1. (Example: similar('dino','bino') = 0.75)
What I want to do is to iterate all items in each sublist of x with all items in list y. And find the domain with the highest similarity for each sublist of x.
My expected output would be:
['smart phones', NaN, 'fruits']
Here's my code so far:
x = [['phones', 'galaxy samsung', 'iphone'],[],['fruit', 'food']] ##each sublist refers to one user
y = ['fruits', 'smart phones', 'fishing', 'cars'] ##domains
point = [0] * len(x)
best_dom = ['n'] * len(x)
for list in x:
i=0
for query in list:
for dom in y:
sim = similar(query,dom)
if sim > point[i]:
point[i] = sim
best_dom[i] = dom
i = i+1
print(best_dom)
But this is the output I'm getting:
['fruits', 'n', 'n']