algorithm - In Python, how do you find the index of the first value greater than a threshold in a sorted list? -


In Python, how do you find the pointer to a value greater than the threshold in the ordered list?

I can think of several ways of doing this (linear search, hand written vignemy, ..), but I am looking for a skilled way of doing it efficiently. Since this is probably a very common problem, I'm sure some people can help!

Thank you!

import bisect l = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] bisect.bisect (l, 55) # returns 7 >

Compare it with linear search:

  Timet bisect.bisect (l, 55) # 375ns timeit next ((i for i, n (n) For N (N), LN (L)) # (Next) 1.93us for L & A (N) N    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -