pip install python-Levenshtein python import Levenshtein def spell_check(word, vocabulary): min_distance = float('inf') suggested_word = '' for vocab_word in vocabulary: distance = Levenshtein.distance(word, vocab_word) if distance < min_distance: min_distance = distance suggested_word = vocab_word return suggested_word suggested_word = spell_check(input_word, vocabulary) print(f"Suggested word for '{input_word}' is '{suggested_word}'")


上一篇:
下一篇:
切换中文