Q:

I need to count letter frequency and save the letter and it's freq as variable

the file input I get looks like this.
TCCATCTACT
GCGCTTCCTG
TCCATCTACC
TGCGCCCTTA
TCGTACTATC
TTTCGCCACC
TCACGCTTAC
ACCCTGCCGC
CACCTACGCC
CTTCAGCACC

My current code is
def readFile(fileName):
    symbTable = dict()
    with open (fileName, 'r') as f:
        for line in f:
            c = Counter(line)
            symbTable ['A'] = c['A']
            symbTable ['C'] = c['C']
            symbTable ['T'] = c['T']
            symbTable ['G'] = c['G']
    print(symbTable)
    for sym, freq in symbTable.items():
        SymObjList = []
        SymObjList.append(SymbolObject(sym, freq, ""))
        print(SymObjList)
    return symbTable, SymObjList

The problem is that my program is only working for one line in the file. How can I get it to find the letter frequency throughout the entire file?

A:

You're very close:
import collections

def readFile(filename):
    with open(filename) as infile:
        counts = collections.Counter(char for line in infile for char in line)
    symObjList = []
    for nuc in "ATCG":
        symObjList.append(SymbolObject(nuc, counts[nuc], ""))
        print(nuc, "appears", counts[nuc], "times")

    return {k:counts[k] for k in "ATCG"}, symObjList

