title: Using a range as a dictionary index in Python
body: <p>Is it possible to do something like:</p>
  
  <pre><code>r = {range(0, 100): 'foo', range(100, 200): 'bar'}
  
  print r[42]
  
  &gt; 'foo'
  </code></pre>
  
  <p>So I would like to use a numeric range as part of a dictionary index. To make things more complicated I would also like to use multi-indexes like <code>('a', range(0,100))</code>. So the concept should be ideally expandable to that. Any suggestions?</p>
  
  <p>A similar question was asked as <a href="https://stackoverflow.com/q/13464143/2075003">here</a>, but I am interested in a comprehensive implementation as opposed to the different approaches of that question.</p>