擅长:python、mysql、java
<pre><code>def shorten_title(title, max_length):
return title[:max_length + 1]
</code></pre>
<p>那怎么样?在</p>
<p>好吧,不用分词,你需要这样:</p>
^{pr2}$
<p>以下是我看到的结果:</p>
<pre><code>print shorten_title("really long long title", 12)
print shorten_title("short", 12)
print shorten_title("reallylonglongtitlenobreaks", 12)
really long
short
reallylonglon
</code></pre>
<p>我试图保持代码和逻辑与原始海报相似,但肯定有更多的Python式的方法来做到这一点。在</p>