A problem (possibly the problem) is the lines which use the get function:
count = frequency.get(word,0)

Since the dictionary is empty at the start of the loop, the get function is
passing a value of 0 to count and count1.
The subsequent updates to the dictionary are applying a value of zero

As a result, the file being written to contains count values of 0 for each
word.

Possible fix is to replace this:

count = frequency.get(word,0)
count1 = frequency.get(word1,0)
if word1 == word:
    frequency[word] = count + count1
else:
    frequency[word] = count

with this:

if word1 == word:
    if word in frequency:
        frequency[word] += 1
    else:
        frequency[word] = 1
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to