Skip to content

Commit dc3d514

Browse files
authored
Create SpellChecker.py
1 parent 55c0fec commit dc3d514

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

SpellChecker.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from english_words import get_english_words_set
2+
from rich import print
3+
4+
wordList = get_english_words_set(['web2'], lower=True)
5+
6+
def CheckWords(argWordList: str) -> list[str]:
7+
"""Checks if words are correct by looping through provided string and checking if the lowered string is in the Standard English Dictionary"""
8+
9+
checked = []
10+
11+
for word in argWordList.split():
12+
if word.casefold() in wordList:
13+
checked.append(f"[green]{word}[/green]")
14+
else:
15+
checked.append(f"[red]{word}[/red]")
16+
17+
return checked
18+
19+
# Main Loop
20+
while True:
21+
userInput = input("Please type in a sentence and press enter to check: ")
22+
23+
checkedWorldList = CheckWords(userInput)
24+
25+
# Turns List to string
26+
consoleOutput = " ".join(checkedWorldList)
27+
28+
print(consoleOutput)

0 commit comments

Comments
 (0)