title: using bisect on list of tuples but compare using first value only
body: <p>I read <a href="https://stackoverflow.com/questions/20908047/using-bisect-in-a-list-of-tuples">that question</a> about how to use <code>bisect</code> on a list of tuples, and I used that information to answer <a href="https://stackoverflow.com/questions/42145924/replace-a-loop-in-python-with-the-equivalent-of-a-matlab-find">that question</a>. It works, but I'd like a more generic solution.</p>
  
  <p>Since <code>bisect</code> doesn't allow to specify a <code>key</code> function, if I have this:</p>
  
  <pre><code>import bisect
  test_array = [(1,2),(3,4),(5,6),(5,7000),(7,8),(9,10)]
  </code></pre>
  
  <p>and I want to find the first item where <code>x &gt; 5</code> for those <code>(x,y)</code> tuples (not considering <code>y</code> at all, I'm currently doing this:</p>
  
  <pre><code>bisect.bisect_left(test_array,(5,10000))
  </code></pre>
  
  <p>and I get the correct result because I <em>know</em> that no <code>y</code> is greater than 10000, so <code>bisect</code> points me to the index of <code>(7,8)</code>. Had I put <code>1000</code> instead, it would have been wrong.</p>
  
  <p>For integers, I could do </p>
  
  <pre><code>bisect.bisect_left(test_array,(5+1,))
  </code></pre>
  
  <p>but in the general case when there may be floats, how to to that without knowing the max values of the 2nd element?</p>
  
  <pre><code>test_array = [(1,2),(3,4),(5.2,6),(5.2,7000),(5.3,8),(9,10)]
  </code></pre>
  
  <p>I have tried this:</p>
  
  <pre><code>bisect.bisect_left(test_array,(min_value+sys.float_info.epsilon,))
  </code></pre>
  
  <p>and it didn't work, but I have tried this:</p>
  
  <pre><code>bisect.bisect_left(test_array,(min_value+sys.float_info.epsilon*3,))
  </code></pre>
  
  <p>and it worked. But it feels like a bad hack. Any clean solutions?</p>