擅长:python、mysql、java
<p>下面是在Python集合中迭代计数器的示例:</p>
<pre><code>>>>def counterIterator():
import collections
counter = collections.Counter()
counter.update(('u1','u1'))
counter.update(('u2','u2'))
counter.update(('u2','u1'))
for ele in counter:
print(ele,counter[ele])
>>>counterIterator()
u1 3
u2 3
</code></pre>