title: Fastest way to search if a coordinate is inside a cube
body: <p>In my code, I am constantly receiving a stream of 3D integer coordinates (x,y,z).   Each coordinate has to be checked against a list of regions, to see if it is in those regions.  Each region is defined by the opposing high and low coordinates.  If the code finds the coordinate is in a region, it takes further action, otherwise it simply exits to continue looking for a match to another region or exits entirely if no region matched.</p>
  
  <p>Since this is happening so fast, I want to get through the whole list of regions as quickly as possible, create a match, or determine it's not a match for any, and move on to the next coordinate.  What i am doing presently 'works' and is nice and readable (to me), but needs some optimization:</p>
  
  <pre><code>firstcorner = self.regions["regions"][name]["pos1"]
  secondcorner = self.regions["regions"][name]["pos2"]
  Xmin = firstcorner[0] - 1  # XXXXXXX
  Ymin = firstcorner[1] - 1
  Zmin = firstcorner[2] - 1
  Xmax = secondcorner[0] + 1  # XXXXXXXX
  Ymax = secondcorner[1] + 1
  Zmax = secondcorner[2] + 1
  BX = position[0]  # XXXXXXX
  BY = position[1]
  BZ = position[2]
  inX = (BX &gt; Xmin) and (BX &lt; Xmax)  # XXXXXXXX
  inZ = (BZ &gt; Zmin) and (BZ &lt; Zmax)
  inY = (BY &gt; Ymin) and (BY &lt; Ymax)
  if inX and inY and inZ: 
  </code></pre>
  
  <p>I thought about nesting this such that it would match the X items first; if the X falls inside the coordinates, only then try to see if Z, and finally Y... </p>
  
  <p>What can I do to create the fastest Python 2.7 code? </p>