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("\n")
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)
this code outputs:
helo
goin
ist
i want it to output :
helo #tab# 3 4
goin #tab# 1 2