title: Python: how to slice a dictionary based on the values of its keys?
body: <p>Say I have a dictionary built like this:</p>
  
  <p><code>d={0:1, 1:2, 2:3, 10:4, 11:5, 12:6, 100:7, 101:8, 102:9, 200:10, 201:11, 202:12}</code></p>
  
  <p>and I want to create a subdictionary <code>d1</code> by slicing <code>d</code> in such a way that <code>d1</code> contains the following keys: <code>0, 1, 2, 100, 101, 102</code>. The final output should be:</p>
  
  <p><code>d1={0:1, 1:2, 2:3, 100:7, 101:8, 102:9}</code> </p>
  
  <p><strong>Is there an efficient Pythonic way of doing this, given that my real dictionary contains over 2,000,000 items?</strong></p>
  
  <p>I think this question applies to all cases where keys are integers, when the slicing needs to follow certain <em>inequality rules</em>, and when the final result needs to be a bunch of slices put together in the same dictionary.</p>