Advertisement
Ihmemies

Spellchecker

Jun 22nd, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. # tee ratkaisu tänne
  2.  
  3. def spellchecker(dict: dict,spellcheck_text: str):
  4.     words_case = spellcheck_text.split()
  5.     words_lcase = []
  6.     checked = ""
  7.     # all strings to lowercase for comparison
  8.     for val in words_case:
  9.         words_lcase.append(val)  
  10.  
  11.     for val in words_lcase:
  12.         #print(dict["python"])
  13.         if val.lower() in dict.keys():
  14.             checked += f"{val} "
  15.         else:
  16.             checked += f"*{val}* "
  17.  
  18.     checked.rstrip()
  19.     print(checked)
  20.    
  21. def load_dict(filename):
  22.     dict = {}
  23.     with open(filename) as file:
  24.         for word in file:
  25.             dict[word.strip()] = 1
  26.  
  27.     return dict
  28.  
  29. def main():
  30.     dict = load_dict("wordlist.txt")
  31.     spellcheck_text = input("Write text:") #"We use ptython to make a spell checker"
  32.     spellchecker(dict, spellcheck_text)
  33.  
  34. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement