how to write add frequency in particular file by reading a csv file and then making a new file of multiple csv file by adding frequency

SANS SANTOSH sanscsantosh at gmail.com
Tue Jun 27 15:36:26 EDT 2017


On Sat 24. Jun 2017 at 13:27, Mark Byrne <mbyrnepr2 at gmail.com> wrote:

> 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
>



More information about the Python-list mailing list