why is this dictionary line number count not working?

Posted by jad on Stack Overflow See other posts from Stack Overflow or by jad
Published on 2010-05-24T04:04:19Z Indexed on 2010/05/24 4:10 UTC
Read the original article Hit count: 212

Filed under:

i have this piece of code the last bit of the code starting from d = {} im trying to print the words with its line number located in the text but it is not working its only printing the words anyone know why ??? need help ASAP

import sys
import string

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

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

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

d = {}
counter = 0
for lines in text:
    counter += 1
if word not in d:
    d[words] = [counter]
else:
    d[words.append[counter]
print(word, d)

© Stack Overflow or respective owner

Related posts about python