title: Which is the fastest way to search a value within a set of many "range" objects in Python
body: <p>I have a list of many Python objects like this:</p>
  
  <pre><code>class RangeClass(object):
  
      def __init__(self,address,size):
          self.address=address
          self.size=size
          #other attributes and methods...
  </code></pre>
  
  <p>Then, I have a list (rangelist) of RangeClass objects.</p>
  
  <p>I need to find within which range a given value is.</p>
  
  <p>I can use some code like this:</p>
  
  <pre><code>for r in ragelist:
      if(value&gt;=r.address and value&lt;(r.address+r.size)):
          return r
  return None
  </code></pre>
  
  <p>But I think there is a faster way. Ranges have arbitrary size, but we can assume that they don't overlap.</p>
  
  <p>Thank you. </p>