I have a number of correctly spelled names in a list
L_name = ['Julia', 'John', 'James', 'Jay', 'Jordan']
And I have a list of results from a form where people entered their name
L_entries = ['Julie', 'John', 'Jo', 'Jamie', 'Jamy', 'James', 'Jay', 'Jordan']
Now I want to iterate over both list, calculate the fuzz.ratio (from fuzzywuzzy) to determine how close the name entered in the form is to the ones in the list of names I know. Then I want to create a list of suggestions with the respective ratio in a second. It shoud of course have the same length as the entries and start with 0 and '' respectively for each entry.
L_ratio = [0] * len(L_entries)
L_suggestion = [''] * len(L_entries)
Now I do know that it is considered bad style to change lists in for loops and it also doesn't work for me. I will do it anyway to show what I hope to get in the end.
for n in L_name:
for e,r,s in zip(L_entries,L_ratio,L_suggestion):
ratio = fuzz.ratio(n, e)
if ratio > r:
r = ratio
s = n
else:
r = r
s = s
So basically, I want to interate over all the names I know and compare them to each of the ones entered in the form. If the name is more similar (i.e. has a higher ratio) than the one tried before, I want to take it as (new) suggestion, otherwise I keep the one before.