<p>我怎样才能减少这种情况?你知道吗</p>
<p><code>item</code>始终是一个字符串</p>
<pre><code>for item in list_of_items:
if ('beans' in item or 'apple' in item or 'eggs' in item or 'banana' in item) and ('elephant' not in item) or 'chicken' not in item:
print(item)
</code></pre>
<p>我的意思是,我能不能给你一张单子来检查每一种可能性?你知道吗</p>
<p>可以将<code>any</code>与生成器或列表一起使用:</p>
<pre><code>if any(word in item for word in ['apple', 'beans', 'eggs', 'banana', 'elephant', 'chicken')):
</code></pre>