我試圖建立我的話第一個迭代器文本:迭代器的話返回字符
def words(text):
regex = re.compile(r"""(\w(?:[\w']*\w)?|\S)""", re.VERBOSE)
for line in text:
words = regex.findall(line)
if words:
for word in words:
yield word
如果我只用這條線words = regex.findall(line)
我檢索列表的所有的話,但如果我使用的功能並做一個NEXT()它將會逐個返回文本字符。
任何想法我做錯了什麼?
什麼是'text'?一個字符串?然後,當你迭代'for line in text'時,它將迭代單個字符... –
你想分割空白嗎?爲什麼不使用'text.split()'? –