【发布时间】:2017-04-26 17:45:47
【问题描述】:
f = open('sentences.txt')
lines = [line.lower() for line in f]
print lines[0:5]
words = re.split("\s+", lines[0:5])
使用“打印”它工作得非常好,但是当我尝试在 re.split() 内部做同样的事情时,我得到一个错误“TypeError:预期的字符串或缓冲区”
【问题讨论】:
-
也许您可以使用五个单独的字符串调用
split五次,而不是将五个字符串传递给split。 -
你想做什么?
-
听起来有点像XY problem。
标签: python regex python-2.7