title: if statement whilst slicing
body: <p>I have a number of lists that I am slicing, such that (using example data):</p>
  
  <pre><code>midpoint = [[0.2], [0.5], [0.6]]
  Values = [[0.1, 0.3, 0.6, 0.8], [0.2,0.3,0.5,0.7], [0.2,0.5,0.6,0.9]]
  numbers = numpy.arange(0, len(Values), 1) 
  </code></pre>
  
  <p>I then have a loop that finds the index position from <code>numbers</code> of the first value that is greater or less than the <code>midpoint</code> value. I have:</p>
  
  <pre><code>for i in range(len(Values)):
      indexgtr = numbers[Values[i]&gt;=midpoint[i]][-1] # The position of the first number larger than the midpoint
      indexlt = numbers[Values[i]&lt;=midpoint[i]][0] # The position of the first number larger than the midpoint
  </code></pre>
  
  <p>I then use these index positions to return values from some other lists that I have.</p>
  
  <p>The problem I have is that sometimes there is no value greater or less than the midpoint so <code>indexgtr</code> or <code>indexlt</code> return an empty list <code>[]</code> and I get the error <code>IndexError: index 0 is out of bounds for axis 0 with size 0</code>.</p>
  
  <p>Is there something that I could add that would catch this and substitute a value of 0 into the empty list?</p>