擅长:python、mysql、java
<p>我建议根据<code>i</code>进行切片<code>words</code>:</p>
<pre><code>print(words[i-5:i+6])
</code></pre>
<p>(这将是你评论的地方)</p>
<p>或者,如示例所示打印:</p>
^{pr2}$
<p>为了解释这个词出现在前5位:</p>
<pre><code>if i > 5:
print("...", " ".join(words[i-5:i+6]), "...")
else:
print("...", " ".join(words[0:i+6]), "...")
</code></pre>
<p>另外,<code>find</code>并没有做你认为的那样。如果<code>find()</code>找不到字符串,则返回<code>-1</code>,该值在If语句中使用时计算结果为<code>True</code>。尝试:</p>
<pre><code>if word in words[i].lower():
</code></pre>