Hi, I need to create a spell checking program where:
- the dictionary is loaded in as a set()
- the 2nd file is input by the user
- all words that are not in the dictionary are added to a list and printed out

My code so far is:
Dictionary = set(open("e:/assignment/dictionary.txt"))
SearchFile = open(input("Please Enter a File Path: "))
WordList = set()

for line in SearchFile:
SearchFile.readline()
if line in Dictionary:
SearchFile.readline()
else:
WordList.add(line)
SearchFile.readline()

print(WordList)


The current results it gives me are a mixture of words that are in the dictionary file, but also the words that aren't.

Please Help, any help is greatly appreciated!

Recommended Answers

All 4 Replies

I would suggest that you print Dictionary to make sure that it is in the form you require. You only read the Search file one line at a time:

Dictionary = set(open("e:/assignment/dictionary.txt"))
print Dictionary

SearchFile = open(input("Please Enter a File Path: "))
WordList = set()     ## WordList is a set not a list

for line in SearchFile:
    line = line.strip()
    if line not in Dictionary:
        WordList.add(line)

print(WordList)

Take a look at the Python Style Guide when you have time http://www.python.org/dev/peps/pep-0008/ The variable name conventions make it easier for others to understand your code. Also include your code in code blocks the next time (the # symbol at the top) as indentation is significant in Python.

commented: Thankyou a million, im only a beginner at python and this was killing me. Cheers +0

Here is a good text to try with your spell checker program:

Eye halve a spelling chequer
It came with my pea sea
It plainly marques four my revue
Miss steaks eye kin knot sea.

Eye strike a key and type a word
And weight four it two say
Weather eye am wrong oar write
It shows me strait a weigh.
As soon as a mist ache is maid
It nose bee fore two long
And eye can put the error rite
Its rare lea ever wrong.

Eye have run this poem threw it
I am shore your pleased two no
its letter perfect awl the weigh
My chequer tolled me sew.

Yes, this should work better:

Dictionary=set(open("e:/assignment/dictionary.txt").read().split())

Yes, this should work better:

Dictionary=set(open("e:/assignment/dictionary.txt").read().split())
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.