【发布时间】:2011-09-10 03:18:36
【问题描述】:
从文本块中分割最后一个单词的最佳方法是什么?
我能想到
- 将其拆分为一个列表(按空格)并删除最后一项,然后重新连接该列表。
- 使用正则表达式替换最后一个单词。
我目前正在采用方法#1,但我不知道如何连接列表...
content = content[position-1:position+249] # Content
words = string.split(content, ' ')
words = words[len[words] -1] # Cut of the last word
非常感谢任何代码示例。
【问题讨论】:
标签: python split concatenation word text-segmentation