title: stumped getting key value from a comprehension
body: <p>Im trying to figure out how to get values from comprehension that is almost working. From this data ..</p>
  
  <pre><code>{'rock': {}, 'coal1': {'gold1': {'data': ['g1']}}, 'coal2': {'gold3': {'data': ['g3']}, 'gold2': {'data': ['g2']}}}
  </code></pre>
  
  <p>.. im trying to extract the gold key data into simple dict. i.e a dict of <code>{ gold : {'data' : [...]} }</code> items essentially ripping out the coal keys from the data.  </p>
  
  <p>in other words from this .. </p>
  
  <pre><code>{
    "coal2": {
      "gold3": {
        "data": [
          "g3"
        ]
      },
      "gold2": {
        "data": [
          "g2"
        ]
      }
    },
    "coal1": {
      "gold1": {
        "data": [
          "g1"
        ]
      }
    },
    "rock": {}
  }
  </code></pre>
  
  <p>to this format</p>
  
  <pre><code>{
    "gold3": {
      "data": [
        "g3"
      ]
    },
    "gold1": {
      "data": [
        "g1"
      ]
    },
    "gold2": {
      "data": [
        "g2"
      ]
    }
  }
  </code></pre>
  
  <p>That is almost working. This gets rid of the rock.</p>
  
  <pre><code>&gt;&gt;&gt; {k:d for k,d in data.items() if k != 'rock'}
  {'coal2': {'gold3': {'data': ['g3']}, 'gold2': {'data': ['g2']}}, 'coal1': {'gold1': {'data': ['g1']}}}
  </code></pre>
  
  <p>And getting the values gets rid of the coal keys.</p>
  
  <pre><code>&gt;&gt;&gt; [v for v in {k:d for k,d in data.items() if k != 'rock'}.values()]
  [{'gold3': {'data': ['g3']}, 'gold2': {'data': ['g2']}}, {'gold1': {'data': ['g1']}}]
  </code></pre>
  
  <p>But i cant figure out how to get from this</p>
  
  <pre><code>&gt;&gt;&gt; for i in [v for v in {k:d for k,d in data.items() if k != 'rock'}.values()] : print(i)
  ...
  {'gold3': {'data': ['g3']}, 'gold2': {'data': ['g2']}}
  {'gold1': {'data': ['g1']}}
  </code></pre>
  
  <p>to the desired structure. And it would be sweet if it could all be done with comprehensions.  Does anyone know how to accomplish this ?</p>
  
  <p>EDIT:
  Both answers was amazing and I wish i could accept both. I like not importing anything but I accept @blhsing itertools version just because it is easier to comprehend and its a fraction better performance. BTW rock must be discarded even it has values so i could not bypass <code>if k != 'rock'</code>. So here is the results and... Thanks guys. </p>
  
  <pre><code>&gt;&gt;&gt; import timeit
  &gt;&gt;&gt; data = {'rock': {'type':'pebble'}, 'coal1': {'gold1': {'data': ['g1']}}, 'coal2': {'gold3': {'data': ['g3']}, 'gold2': {'data': ['g2']}}}
  &gt;&gt;&gt; timeit.timeit( "dict(kv for x in (v for v in {k:d for k,d in data.items() if k != 'rock'}.values()) for kv in x.items())" ,  setup="from __main__ import data")            
  2.6714617270044982
  &gt;&gt;&gt;
  &gt;&gt;&gt; timeit.timeit( "dict(chain.from_iterable(g.items() for g in {k:d for k,d in data.items() if k != 'rock'}.values()))" , setup="from __main__ import data; from itertools import chain")
  2.22612579818815
  &gt;&gt;&gt;
  </code></pre>