python bisect on an array of floats

989 views Asked by At

I was wondering how to use bisect or any other binary search method on an array of floats. So for instance let us say that I have an array of floats such as

list_floats = [11.1,22.2,33.3,44.5,55.6,66.7]

and I want to find the position another number should be inserted (e.g. if I input 22.3 the output of the function should be 2). I have tried with bisect(list_floats,22.3) thinking that it would return either 22.2 or 33.3 but it seems to round everything to integers. Am I doing something wrong? Can anyone suggest a method around this problem? Cheers!

0

There are 0 answers