title: Using List Comprehension with Dictionaries in Python
body: <p>I'm trying to get my head around list comprehensions and I can understand the basics of how they work but I get the feeling I should be able to do something with my code here that I just can't seem to get working.</p>
  
  <p>Given a dictionary:</p>
  
  <pre><code>{2: {11},  9: {11, 8, 10}, 10: {11, 3}, 11: {7, 5},  8: {7, 3}}
  </code></pre>
  
  <p>There are a couple of snippets that I feel I should be able to reduce to fewer lines if I knew better:</p>
  
  <pre><code>for k, v in d.items():
      dag[k] = v
      for val in v:
          if val not in d.keys():
              dag[val] = None
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>t = []
  for k, v in d.items():
      if not v:
          t.append(k)
          d.pop(k)
  </code></pre>
  
  <p>My attempts have been variations on:</p>
  
  <pre><code>for [k, v in d.items() if not v]:
  </code></pre>
  
  <p>But that keeps telling me it needs an else statement and none of what I have read has helped answer how/if this is possible.</p>