Way to get specific keys from dictionary
<p>I am looking for a way to get specific keys from a dictionary. </p>

<p>In the example below, I am trying to <code>get all keys except 'inside'</code></p>

<pre><code>&gt;&gt;&gt; d
{'shape': 'unchanged', 'fill': 'unchanged', 'angle': 'unchanged', 'inside': 'a-&gt;e', 'size': 'unchanged'}
&gt;&gt;&gt; d_keys = list(set(d.keys()) - set(["inside"]) )
&gt;&gt;&gt; d_keys
['shape', 'fill', 'angle', 'size']
&gt;&gt;&gt; for key in d_keys:
...     print "key: %s, value: %s" % (key, d[key])
...
key: shape, value: unchanged
key: fill, value: unchanged
key: angle, value: unchanged
key: size, value: unchanged
</code></pre>

<p>Is there a better way to do this than above?</p>

<p>you can do it with a dict comprehension for example to only get evens.</p>

<pre><code>d = {1:'a', 2:'b', 3:'c', 4:'d'}
new_d = {k : v for k,v in d.items() if k % 2 == 0}
</code></pre>

<p>for your case because of complaints.</p>

<pre><code>d = {'shape': 'unchanged', 'fill': 'unchanged', 'angle': 'unchanged',         'inside': 'a-&gt;e'}
new_d = {k:v for k,v in d.items() if k != 'fill'}
#you can replace the k != with whatever key or keys you want
</code></pre>

python dictionary