<p>当消息包含列表<code>block</code>中的任何项时,将<code>flag</code>值设置为<code>True</code>。在</p>
<ol>
<li>获取<code>block</code>列表并通过<code>for</code>循环迭代列表中的每个项。在</li>
<li>默认情况下,将<code>flag</code>的值设置为<code>False</code>,表示消息不包含任何阻止列表项。在</li>
<li>当消息中的<code>block</code>列表中的项时,将<code>flag</code>的值设置为<code>True</code>。在</li>
<li>使用<code>break</code>语句停止<code>for</code>循环迭代。在</li>
</ol>
<p>例如</p>
<pre><code>>>> block = ["damn", "shit"]
>>> msg = "test masf to check shit or damn"
>>> flag = False
>>> for i in block:
... if i in msg:
... flag = True
... break
...
>>> flag
True
>>>
</code></pre>
<hr/>
<p>更新时间:</p>
<ol>
<li>设置<code>block</code>列出单词。在</li>
<li>创建阻止列表单词字符列表。在</li>
<li>从输入字符串中删除标点符号。在</li>
<li>将字符串拆分为单词。在</li>
<li>拆分单词并从该单词创建字符序列列表。在</li>
<li>检查阻止列表字符列表中存在的字符序列列表。在</li>
</ol>
<p>代码:</p>
^{pr2}$
<p>输出:</p>
<pre><code>vivek@vivek:~/Desktop/stackoverflow$ python 16.py
The word `damn` from block list is presnt in input 'True test case ? daaaammmmnnnnn.,'
The word `damn` from block list is presnt in input 'True test case ? normal damn.,'
No word from block list is presnt in input 'False test case ? nothing when sequance aaammdddnnn..'
No word from block list is presnt in input 'False test case ? nothing..'
No word from block list is presnt in input 'True test case ? Handle daaaammaaaammnnnnn.,'
</code></pre>