擅长:python、mysql、java
<p>一种方法是使用<a href="https://docs.python.org/3/library/collections.html#collections.Counter" rel="nofollow noreferrer">^{<cd1>}</a>:</p>
<pre><code>from collections import Counter
l = [1, 1, 3, 4, 5, 5, 5, 5] # find the number of 5
c = Counter(l)
print(c[5]) # 4
</code></pre>
<p>如果您想知道其他项的出现次数,这将比<code>l.count(5)</code>更有效。(如果只关心一项,效率会降低)。你知道吗</p>