i currently have this piece of code
i need to create a dictionary that prints the incorrect word and the line number where it is incorrect.
words [] # is my txt file
text1 [] # is my list of incorrect words
i am new to programming and dont know much syntax so hope you can help and tell me what i have done wrong or need to change cheers.

d = {}
counterline = 0
for lines in words:
    text1 = lines.split()
    counterline += 1
    if text1 not in d:
        d[text1] = [counterline]
    if text1 in d:
        d[text1].append[counterline]
        print(text1,    d[counterline])

Edited 6 Years Ago by vegaseat: added code tags

This should get you started, it will have to be tweaked depending on the infile that you are using.

def main():
    
    d = {}
    text1 = ["dog","cat"]
    infile = open("words.txt","r")  #Opening words.txt, r is for read
    counter = 0
    
    for line in infile:
        words = line.split(",") #Using "," for delimiter
        counter += 1
        for word in words:
            if word in text1:   #If the word is incorrect
                d[word] = counter   #Adds to the dictionary
    
    #printing out the dictionary
    print "The Incorrect Words are:\n"
    for iWord, count in d.iteritems():
        print "%s Found at line number %i" % (iWord,count)
        
if __name__ == '__main__':
    main()
import sys
import string

words = []
infile = open(sys.argv[1], 'r').read()
for punct in string.punctuation:
    infile = infile.replace(punct, "")
    words = infile.split()

dict = open(sys.argv[2], 'r').read()
dictset = []
dictset = dict.split()

text1 = []
text1 = list(set(words) - set(dictset))
text1 = [text.lower() for text in text1]
text1.sort()

def main():
    d = {}
    counter = 0
    for line in infile:
        soccer = line.split(",")
        counter += 1
        for word in words:
            if word in text1:
                d[word] = counter
    print("The Incorrect Words are:\n")
    for iWord, count in d.iteritems():
        print("%s Found at line number %i" % (iWord, count)

this is what ive got but it gives me a syntx error:

File spellcheck2.py, line 47
     ^
syntax error invalid syntax

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.