擅长:python、mysql、java
<p>您可以检查当前键是否为<code>'title'</code>,如果是,则调用函数并将当前值传递给函数:</p>
<pre><code>new_dict = {a:strip_non_en(b, words) if a == 'title' else b for a, b in meta_data.items()}
</code></pre>
<p>另外,您可以稍微更改函数<code>strip_non_en</code>,以便参数<code>words</code>是可选的。这样,就不必每次都传递<code>words</code>:</p>
<pre><code>def strip_non_en(string, words=words):
" ".join(w for w in nltk.wordpunct_tokenize(string)\
if w.lower() in words or not w.isalpha())
return string
new_dict = {a:strip_non_en(b) if a == 'title' else b for a, b in meta_data.items()}
</code></pre>