I\'m writing a spell checking function and I have a text file that looks like this
teh the
cta cat
dgo dog
dya day
frmo from
memeber member
Th
You problably want to use split to get the words, then map the misspelled word to the correctly spelled one:
def spell():
dictCorrect={}
with open('autoCorrect.txt','r') as corrections:
for line in corrections:
wrong, right = line.split(' ')
dictCorrect[wrong] = right
return dictCorrect
Use this:
with open('dictionary.txt') as f:
d = dict(line.strip().split(None, 1) for line in f)
d
is the dictionary.
disclaimer: This will work for the simple structure you have illustrated above, for more complex file structures you will need to do much more complex parsing.