<p>我还在学习python,我有下面的代码,但它不起作用:</p>
<pre><code>from itertools import *
startword = ["start",]
stopword = ["stop",]
text = "this is a text that starts with some test stuff and then after that it stop right here!"
for i in islice(text.split(" "), startword, stopword):
print i
</code></pre>
<p>我试着在开始和结束之间打印单词,而不知道中间有多少个单词。
从这个错误看来,我需要一个整数作为islice的启动和停止参数。以下是错误“<code>ValueError: Indices for islice() must be None or an integer: 0 <= x <= maxing.</code>”
还有我能用的其他itertool吗?!在</p>
<p>谢谢</p>