Files
Laboratori-PY/spellcheck.py
2024-03-22 17:01:42 +01:00

42 lines
838 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from os import WNOHANG
def clean(word: str):
a = len(word)
while True:
word = word.strip("()[]{}!?.,<>:;-_`")
if a == len(word):
break
a = len(word)
return word
def file_to_set(filename: str, clear: bool):
dfio = open(filename, "r", encoding="cp1252")
words = set()
for line in dfio:
for word in line.strip().split():
if clear:
word = clean(word)
if word == "":
continue
words.add(word.lower())
dfio.close()
return words
def main():
dictionary = file_to_set("words.txt", False)
document = file_to_set("ge.txt", True)
misspelling = dictionary.difference(document)
for word in sorted(misspelling):
print(word)
main()