Find the closest matching string python

Karan Goyal
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.

--

--

Karan Goyal
Karan Goyal

Written by Karan Goyal

Full Stack Developer, Top Rated on Upwork, Worked on 90+ jobs in past 9 months and all jobs are rated 5 stars, coding is fun, and always looking forward to code

No responses yet