I have a set of reference words (spelled correctly) and I need to take a user input word. The input word is compared with the reference list using levenshtein distance and I need to return the word from reference list that has the lowest cost. Furthermore, that reference list is sorted by frequencies so higher frequencies appear at the top. In case the distance is same for 2 words,the word with higher frequency is returned. "NWORDS" is my reference list sorted according to the frequency. "Candidate" is the user input word.
Code:
for word in NWORDS: #iterate over all words in ref
i = jf.levenshtein_distance(candidate,word) #compute distance for each word with user input
#dont know what to do here
return word #function returns word from ref list with lowest dist and highest frequency of occurrence.