从文本块中分割最后一个单词的最佳方法是什么?
我能想到
- 将其拆分为列表(按空格)并删除最后一项,然后重新连接列表。
- 使用正则表达式替换最后一个单词。
我目前正在采用方法#1,但我不知道如何连接列表......
content = content[position-1:position+249] # Content
words = string.split(content, ' ')
words = words[len[words] -1] # Cut of the last word
非常感谢任何代码示例。