擅长:python、mysql、java
<p>您是否有意使用<code>filter</code>和<code>lambda</code>?如果要获取项目计数,可以使用<code>list</code>类型的<code>count</code>方法:</p>
<pre><code>>>> f = ['black', 'red', 'blue', 'red', 'black', 'red', 'white', 'white', 'orange', 'black', 'orange', 'black', 'red', 'green', 'yellow', 'blue', 'blue', 'purple', 'white', 'yellow', 'green', 'black', 'orange', 'white', 'black', 'blue', 'blue', 'blue', 'orange', 'yellow', 'yellow', 'blue', 'red', 'white', 'yellow', 'blue', 'red', 'yellow', 'yellow', 'white', 'white', 'black', 'purple', 'red', 'orange', 'orange', 'blue', 'orange', 'black', 'red']
>>> f.count("red")
8
</code></pre>