python: find value within range in float array

前端 未结 2 505
生来不讨喜
生来不讨喜 2021-01-27 15:10

I have the following sorted python list, although multiple values can occur:

[0.0943200769115388, 0.17380131294164516, 0.4063245853719435, 
 0.45796523225774904,         


        
2条回答
  •  清酒与你
    2021-01-27 15:48

    >>> vals = [0.0943200769115388, 0.17380131294164516, 0.4063245853719435, 
     0.45796523225774904, 0.5040225609708342, 0.5229351852840304, 
     0.6145136350368882, 0.6220712583558284, 0.7190096076050408, 
     0.8486436998476048, 0.8957381707345986, 0.9774325873910711, 
     0.9832076130275351, 0.985386554764682, 1.0]
    
    >>> import bisect
    >>> bisect.bisect(vals, 0.25)
    2
    

提交回复
热议问题