hey guys, im having some trouble with this. I've got 2 text files, one in a paragraph with some wrong words, and a dictionary file with 1 word in 1 line. Im not sure how to separate the words in the paragraph to become 1 word to 1 line so that i can compare it to the dictionary file. ive put the codes up but if anyone finds anything else wrong with the code please let me know. thanks
import sys
# setText holds the words from the sample text file
setText = set()
# setProperDic holds the words from the dictionary text file
setProperDic = set()
# setWrong holds the incorrect words after comparing each set
setWrong = set()
fText = open(sys.argv[1], 'r')
line = fText.readline( )
while line != '':
setText.add(lin e)
line = fText.readline( )
fText.close()
fProperDic = open(sys.argv[2], 'r')
line = fProperDic.read line()
while line != '':
setProperDic.ad d(line)
line = fProperDic.read line()
fProperDic.clos e()
# Find the values in setText
# that don't exist in setDict
setWrong = setText - setProperDic
# Output each entry seperately
# in alphabetical order
for x in sorted(setWrong ):
print(x)
import sys
# setText holds the words from the sample text file
setText = set()
# setProperDic holds the words from the dictionary text file
setProperDic = set()
# setWrong holds the incorrect words after comparing each set
setWrong = set()
fText = open(sys.argv[1], 'r')
line = fText.readline( )
while line != '':
setText.add(lin e)
line = fText.readline( )
fText.close()
fProperDic = open(sys.argv[2], 'r')
line = fProperDic.read line()
while line != '':
setProperDic.ad d(line)
line = fProperDic.read line()
fProperDic.clos e()
# Find the values in setText
# that don't exist in setDict
setWrong = setText - setProperDic
# Output each entry seperately
# in alphabetical order
for x in sorted(setWrong ):
print(x)
Comment