Count each occurrence of alphabet and store it in a list in Python 3
<p>Suppose I have a string s   </p>

<pre><code>s = "ebber"   
</code></pre>

<p>I want a list x, where x = [1,1,2,2,1]<br>
We see the first occurrence of e so our first element in list x is 1, then we see the first occurrence of b so our next element in our list is 1, then we see our second occurrence of b so our next element in the list is 2, and so on.....     </p>

<p>How do I implement code to get this result in python?</p>

<pre><code>from collections import defaultdict

def count(s):
    d, ls = defaultdict(int), []
    for e in s:
        d[e] += 1 # increment counter of char
        ls.append(d[e]) # add counter
    return ls

count("ebber") # [1, 1, 2, 2, 1]
</code></pre>

python