Created
November 15, 2017 17:01
-
-
Save jeremysinger/3d56651a0b040d48b8a76661a125e54b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f = open('/usr/share/dict/words') | |
# this is where my dictionary lives on my Mac | |
words = f.read().splitlines() | |
# one word per line | |
f.close() | |
# OS complains if we don't close files | |
def spotTheDifference(myword, properword): | |
'''count the number of letter differences between | |
the two string parameters''' | |
numDiffs = 0 | |
i = 0 | |
while i < len(myword) and i< len(properword): | |
if myword[i] != properword[i]: | |
numDiffs = numDiffs+1 | |
i = i+1 | |
numDiffs = numDiffs + abs(len(myword) - len(properword)) | |
return numDiffs | |
def checkAWord(myWord): | |
'''see if a word spellchecks, if not print | |
some suggested corrections''' | |
wordIsGood = False | |
if myWord in words: | |
wordIsGood = True | |
print(myWord, "is correct") | |
else: | |
for i in range(1, 4): | |
for word in words: | |
if spotTheDifference(word, myWord) == i: | |
print("did you mean ... ", word, "?") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment