Counting multiple letter groups in a string
<p>I've been trying to adapt my python function to count groups of letters instead of single letters and I'm having a bit of trouble. Here's the code I have to count individual letters:</p>
<pre><code>my_seq = &quot;CTAAAGTCAACCTTCGGTTGACCTTGAAAGGGCCTTGGGAACCTTCGGTTGACCTTGAGGGTTCCCTAAGGGTT&quot;

def count_letters(str):
    counts = {}
    for c in str:
        if c in counts:
            counts[c]+=1
        else:
            counts[c]=1
    return counts

counts = count_letters(my_seq)
print(counts)
</code></pre>
<p>The function currently spits out counts for each individual letter. Right now it prints this:</p>
<pre><code>{'C': 23, 'T': 30, 'G': 30, 'A': 20}
</code></pre>
<p>Ideally, I'd like it to print something like this:</p>
<pre><code>{'CTA': 2, 'TAG': 3, 'CGC': 1, 'GAG': 2 ... }
</code></pre>
<p>I'm very new to python and this is proving to be difficult.</p>