Untitled
unknown
python
a year ago
1.3 kB
5
Indexable
#Write your code here 1 usage def correct.ord(word): corrected_word = "• consecutive_count = 1 for 1 in range(Len(word)): if word[1]. isalpha) or word[1],isspace(): # Include space characters if i > 0 and word[1] == word{1 - 1]: consecutive_count += 1 if consecutive_count >= 2: continue else: consecutive_count = 1 corrected_word += word[i) print (word) # Remove special characters from the end of the word while corrected word and not corrected_word[-1] .isalpha() and Len(corrected_word) > 1: corrected_word = corrected_word[: -1] # Check if the word has only one character left after corrections if len(corrected_word) == 1: return " # Check if the word is misspelled if Len(corrected_word) > 1 and corrected_word[0]. isupper (): if corrected_word. Lower() != "correct": return " return corrected_word 1 usage def naive-spell_checker (sentence): corrected sentence for word in sentence.split: corrected_word = correct_word(word) if corrected_word: # Check if corrected word is not empty corrected_sentence += corrected_word + • • else: corrected_sentence += word + return corrected_sentence.strip) # If word is empty, retain the original word input_sentence = 'Thitis is a missta%ke, please precrint the correct sentensce* corrected_sentence = naive_spell_checker (input_sentence) print (corrected_sentence)
Editor is loading...
Leave a Comment