<p>好的,所以我想过滤除了<code>a</code>之外的每个字符串,并打印出句子中<code>a</code>个字母的数量:</p>
<pre><code>import string
sentence = "The cat sat on the mat."
for letter in sentence:
print(letter)
</code></pre>
<p>首先,在使用<code>filter</code>函数打印之前,只需删除所有<code>a</code>s。然后,使用<code>count()</code>来计算发生次数</p>
<pre><code>filter(lambda x: x != 'a', sentence)
#Out: 'The ct st on the mt.'
sentence.count('a')
#Out: 3
</code></pre>