Lets say I'm building a rudimentary search engine of sorts. I have a list of strings as the search results, and I want to order the list of search results with the best matching results at the top.
My current code looks like this (named parameters as examples)
import difflib
def order_by_best_match(search_results=["spam", "eggs", "spammy", "eggy"], search_query="spam"):
for result in search_results:
ratio = difflib.SequenceMatcher(None, result, search_query).ratio()
I don't know what to do with ratio
after that. I know I have to sort the list by ratio
, but how would I do that?