擅长:python、mysql、java
<p>如果要排除的字符串列表很大,这里有一个相当可扩展的选项:</p>
<pre><code>exclude = ['lulz', 'lmfao', '.png']
filter_func = lambda s: 'http://' in s and not any(x in s for x in exclude)
matching_lines = filter(filter_func, string_list)
</code></pre>
<p>列表理解选项:</p>
<pre><code>matching_lines = [line for line in string_list if filter_func(line)]
</code></pre>