Skip to content

Instantly share code, notes, and snippets.

@jeremysinger
Created November 15, 2017 17:01
Show Gist options
  • Save jeremysinger/3d56651a0b040d48b8a76661a125e54b to your computer and use it in GitHub Desktop.
Save jeremysinger/3d56651a0b040d48b8a76661a125e54b to your computer and use it in GitHub Desktop.
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