how to print the linenumber of incorrectwords located in a txt file ?

Posted by jad on Stack Overflow See other posts from Stack Overflow or by jad
Published on 2010-05-23T14:46:09Z Indexed on 2010/05/23 14:50 UTC
Read the original article Hit count: 194

Filed under:

i have this piece of code which only prints the line number of the incorrect words. i want it to print the linenumbers of the incorrect words from the txt file. Am i able to modify this code to do that?

# text1 is my incorrect words
# words is my text file where my incorrect word are in 

from collections import defaultdict
d = defaultdict(list)
for lineno, word in enumerate(text1):
    d[word].append(lineno)
print(d)

© Stack Overflow or respective owner

Related posts about python