【发布时间】:2015-02-04 00:38:13
【问题描述】:
我编写了一个标记化函数,它基本上读取字符串表示并将其拆分为单词列表。
我的代码:
def tokenize(document):
x = document.lower()
return re.findall(r'\w+', x)
我的输出:
tokenize("Hi there. What's going on? first-class")
['hi', 'there', 'what', 's', 'going', 'on', 'first', 'class']
期望的输出:
['hi', 'there', "what's", 'going', 'on', 'first-class']
基本上,我希望撇号和连字符在列表中保留为单个单词以及双引号。如何更改我的函数以获得所需的输出。
【问题讨论】:
-
你能按空格分割吗?
标签: python regex list function split