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>When you iterate over a <code>Counter</code> you are iterating over the keys. In order to get the counts at the same time you could do something like:</p>

<pre><code>for i, count in t.items():
    print('{} {}s'.format(count, i))
</code></pre>

python