Way to loop over Counter by number of times present?
<p>I am using collections.Counter and I am trying to loop over the elements. However if I have <code>t=Counter("AbaCaBA")</code> and use a for loop to print each element, it would only print one of each letter:</p>

<pre><code>   for i in t:
       print(i)
</code></pre>

<p>would print:</p>

<pre><code>    a
    C
    A
    b
    B
</code></pre>

<p>How would I loop over it in  a way that would print as many of each letter as there are? As in, 2 A's, 2 a's, 1 b, 1 B, 1 C.</p>

<p>Edit: apparently there is a method called elements() that serves this exact purpose.</p>

<p>Discovered the elements() method shortly after posting this, here: <a href="https://docs.python.org/3/library/collections.html#collections.Counter" rel="nofollow">https://docs.python.org/3/library/collections.html#collections.Counter</a></p>

<p>It returns an iterator that repeats each element as many times as it is counted, ignoring elements with counts&lt;1</p>

<pre><code>    for i in t.elements():
         print(i)
</code></pre>

python