擅长:python、mysql、java
<p>yatu的回答很好,而且很像Python,但是我们可以走得更远!你知道吗</p>
<pre><code>content = "first line \nsecond line\nthird line\netc."
content = '\n'.join(
i if len(i) > 5 else ''
for i in content.splitlines()
)
content
#'first line \nsecond line\nthird line'
</code></pre>
<p>你知道吗str.join公司需要任何iterable,所以这里使用生成器表达式来获得更多pythonicness!你知道吗</p>