擅长:python、mysql、java
<p>我相信这就是你的意思:给予</p>
<pre><code>segmentation1 = [('874', '893'), ('964', '985')]
</code></pre>
<p>你想要:</p>
<pre><code>'874' in segmentation1 # true
'875' in segmentation1 # also true
'893' in segmentation1 # true
'894' in segmentation1 # false
</code></pre>
<p>如果是这样,您可以使用<code>any()</code>函数来实现:</p>
<pre><code>if any(lbound <= index <= ubound for lbound,ubound in segmentation1):
pass # do something
</code></pre>
<p>但要小心。我看到您在示例中使用字符串作为索引,因此比较基于字符串(即“999”>;“1000”)。你知道吗</p>