擅长:python、mysql、java
<p>使用<a href="https://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="nofollow noreferrer">list comprehension</a>和<a href="https://docs.python.org/library/re.html#re.findall" rel="nofollow noreferrer">^{<cd1>}</a>计算<strong>空白的数量</strong>:</p>
<pre><code>import re
vocab = ['he llo','go ing','home work','play foot ball','spring']
num_whitespace = len([w for s in vocab for w in re.findall(r'\s', s)])
print(num_whitespace)
# 5
</code></pre>