Find the closest matching string python
Jan 30, 2023
import difflib
str = 'apple'
str_list = ['ape' , 'fjsdf', 'aerewtg', 'dgyow', 'paepd']
best_match = difflib.get_close_matches(str, str_list)[0]
#SCORE OF BEST MATCHING ELEMENT
score = difflib.SequenceMatcher(None, my_str, best_match).ratio()
This arranges the array with the best match starting from index 0.