擅长:python、mysql、java
<p>请注意,从Python 2.7/3.1开始,此功能将内置到<code>collections</code>模块中,有关更多信息,请参见<a href="http://bugs.python.org/issue1696199" rel="noreferrer">this bug</a>。下面是来自<a href="http://docs.python.org/dev/whatsnew/2.7.html" rel="noreferrer">release notes</a>的示例:</p>
<pre><code>>>> from collections import Counter
>>> c=Counter()
>>> for letter in 'here is a sample of english text':
... c[letter] += 1
...
>>> c
Counter({' ': 6, 'e': 5, 's': 3, 'a': 2, 'i': 2, 'h': 2,
'l': 2, 't': 2, 'g': 1, 'f': 1, 'm': 1, 'o': 1, 'n': 1,
'p': 1, 'r': 1, 'x': 1})
>>> c['e']
5
>>> c['z']
0
</code></pre>