title: How to find the highest number less than target value in a list?
body: <p>I am trying to write a binary search that takes a sorted list and finds the largest number less than a target value:</p>
  
  <pre><code>def binary_max(list, target)
      hi=len(list)-1
      lo=0
      while lo&lt;=hi:
          mid=(hi+lo)//2
          midval=list[mid]
          if midval &gt; target:
              hi=mid-1
          elif midval &lt;= target:
              lo=mid
          if hi==lo:
              break
      return(list[mid])
  pass
  </code></pre>
  
  <p>however when for example there is a list with length 2, hi=1 and the mid value will always be stuck on lo
  is there anyway to avoid this problem?</p>
  
  <p>thanks</p>