Python: Cut off the last word of a sentence?

后端 未结 7 1495
攒了一身酷
攒了一身酷 2020-12-08 09:17

What\'s the best way to slice the last word from a block of text?

I can think of

  1. Split it to a list (by spaces) and removing the last item, then reco
相关标签:
7条回答
  • 2020-12-08 10:06

    If you like compactness:

    ' '.join(content.split(' ')[:-1]) + ' ...'
    
    0 讨论(0)
提交回复
热议问题