title: How to filter a dictionary according to an arbitrary condition function?
body: <p>I have a dictionary of points, say:</p>
  
  <pre><code>&gt;&gt;&gt; points={'a':(3,4), 'b':(1,2), 'c':(5,5), 'd':(3,3)}
  </code></pre>
  
  <p>I want to create a new dictionary with all the points whose x and y value is smaller than 5, i.e. points 'a', 'b' and 'd'.</p>
  
  <p>According to the <a href="http://docs.python.org/library/stdtypes.html#mapping-types-dict" rel="noreferrer">the book</a>, each dictionary has the <code>items()</code> function, which returns a list of <code>(key, pair)</code>  tuple:</p>
  
  <pre><code>&gt;&gt;&gt; points.items()
  [('a', (3, 4)), ('c', (5, 5)), ('b', (1, 2)), ('d', (3, 3))]
  </code></pre>
  
  <p>So I have written this:</p>
  
  <pre><code>&gt;&gt;&gt; for item in [i for i in points.items() if i[1][0]&lt;5 and i[1][1]&lt;5]:
  ...     points_small[item[0]]=item[1]
  ...
  &gt;&gt;&gt; points_small
  {'a': (3, 4), 'b': (1, 2), 'd': (3, 3)}
  </code></pre>
  
  <p>Is there a more elegant way? I was expecting Python to have some super-awesome <code>dictionary.filter(f)</code> function...</p>