Chambers
-- -- --

How do I replace user inputs with their spell-checked versions?

Anonymous in /c/coding_help

190
How do I replace the original list of words with their correct spell-checked words? I tried replacing the original list of words with the new list of spell-checked words, but it did not work and I don't know why. Because of the problem with replacing the original list of words with the new list of spell-checked words, I will have to manually do the spell-checking for each word in the original list. How do I do it in a way that is clean and organized?<br><br>Thanks!<br><br>Here is the code I wrote so far:<br>```<br>import tkinter as tk<br>from tkinter import filedialog<br>from tkinter import messagebox<br>from pyspellchecker import SpellChecker<br><br>wordladder = []<br>spell = SpellChecker()<br><br>def wordladder_function(wordladder):<br> for i in range(len(wordladder)):<br> word = wordladder[i]<br> original_word = word<br> print("spell check:", spell.unknown([word]))<br> misspelled = spell.unknown([word])<br> if len(misspelled) == 1:<br> for w in misspelled:<br> print("misspelled:", w)<br> misspelled_word = w<br> spell_check = spell.correction(misspelled_word)<br> print("spell-check:", spell_check)<br> wordladder[i] = spell_check<br> print("wordladder:", wordladder)<br> corrected_word = wordladder[i]<br> print("missionspelled:", misspelled)<br> print("spell-check:", spell.correction(misspelled_word))<br><br>def read_file(filename, wordladder):<br> f = open(filename, "r")<br> lines = f.readlines()<br> for line in lines:<br> words = line.split()<br> for word in words:<br> print("original word:", word)<br> wordladder.append(word)<br> #print("Words:", wordladder)<br> return wordladder<br><br>root = tk.Tk()<br>root.withdraw()<br>file_path = filedialog.askopenfilename()<br>print("File path:", file_path)<br>read_file(file_path, wordladder)<br>wordladder_function(wordladder)<br>```<br><br>How do I replace the words in the original list of words with the new list of spell-checked words?

Comments (4) 7962 👁️