How to count word frequencies within a file in python
<p>I have a .txt file with the following format,</p>

<pre><code>C
V
EH
A
IRQ
C
C
H
IRG
V
</code></pre>

<p>Although obviously it's a lot bigger then that, this is essentially it.Basically I'm trying to sum how many times each individual string is in the file (each letter/string is on a separate line, so technically the file is C\nV\nEH\n etc. However when I try to convert these files into a list, and then use the count function on, it separates out letters so that strings such as 'IRQ' are ['\n'I','R','Q','\n'] so then when I count it I get the frequencies of each individual letter and not of the strings.</p>

<p>Here is the code that I have written so far,</p>

<pre><code>def countf():
    fh = open("C:/x.txt","r")
    fh2 = open("C:/y.txt","w")
    s = []
    for line in fh:
        s += line
    for x in s:
        fh2.write("{:&lt;s} - {:&lt;d}".format(x,s.count(x))
</code></pre>

<p>What I want to end up with is an output file that looks something like this</p>

<pre><code>C  10
V  32
EH 7
A  1
IRQ  9
H 8
</code></pre>
