这也是最近处理数据的实际需求,找了一些网页,发现大家都总结得不是很清楚,最后参考几位朋友的文章,例如这里:
/oh5W6HinUg43JvRhhB/article/details/79676440
实现了需求,实际上很简单,就是用re包:
import re
pattern="[A-Z]"
new_string=(pattern,lambda x:" "+(0),old_string)
print new_string
的具体使用方法可以参考这里:/tina-python/p/
一些相似的博客文章:/tao_627/article/details/50354110
另外,再总结一个需求,从连续的没有空格的英文字符串中提取出有意义的word,例如tableapplechairtablecupboard提取出:["table", "apple", "chair", "table", ["cupboard", ["cup", "board"]], ...],感觉这个需求也是很有意义的,Stack Overflow上已经有很多讨论和较详细的答案:/questions/8870261/how-to-split-text-without-spaces-into-list-of-words,有人根据这些讨论还开发一个Python包:wordninja,GitHub Repo的链接是:/keredson/wordninja (word忍者)
发现其确实可以针对全是小写字母的字符串处理:
import wordninja
splited_words=(old_string.lower())
print splited_words
感觉这个工具确实造福人类啊!