I've created a simple word count program in python which reads a text file, counts the word frequency and writes the result to another file. The problem is when the word gets repeated, the program writes the initial as well as final count of the same word. For Example, if a word "hello" is repeated say 3 times, the program writes 3 instance of hello in output as :
Word - Frequency Count
hello - 1
hello - 2
hello - 3
The code is:
counts ={}
for w in words:
counts[w] = counts.get(w,0) + 1
outfile.write(w+','+str(counts[w])+'\n')'
Any help would be appreciated. I'm very much new in python.