I read this question about how to use bisecttuples in a list, and I used this information to answer this question . It works, but I would like to get a more general solution.
Since it bisectdoesn’t allow you to specify a function key, if I have this:
import bisect
test_array = [(1,2),(3,4),(5,6),(5,7000),(7,8),(9,10)]
and I want to find the first element where x > 5for these (x,y)tuples (without considering at all y, I am doing this now:
bisect.bisect_left(test_array,(5,10000))
and I get the correct result because I know that no is ygreater than 10000, so it bisectpoints me to an index (7,8). If I put it 1000, it would be wrong.
For integers, I could do
bisect.bisect_left(test_array,(5+1,))
, , , 2- ?
test_array = [(1,2),(3,4),(5.2,6),(5.2,7000),(5.3,8),(9,10)]
:
bisect.bisect_left(test_array,(min_value+sys.float_info.epsilon,))
, :
bisect.bisect_left(test_array,(min_value+sys.float_info.epsilon*3,))
. . - ?