title: The Pythonic way of alternate looping over lists and dicts (combined)
body: <p>Consider the two following variables:</p>
  
  <pre><code>a = [1, 2, 3, 4]
  b = {
      'OK': [1, 3],
      'BAD': [2, 4]
  }
  </code></pre>
  
  <p>Notice that the <code>1</code> in <code>a</code> is basically the same <code>1</code> in <code>b['OK']</code>.</p>
  
  <p><strong>Note:</strong> <code>a</code> may seem irrelevant, but it's there to keep the order of the items (which are <strong>not</strong> sortable, btw) as shown in the example below.</p>
  
  <p>What's the most Pythonic way of looping over those two variable to effectively get those two results:</p>
  
  <pre><code>1: OK
  2: BAD
  3: OK
  4: BAD
  </code></pre>
  
  <p>or </p>
  
  <pre><code>OK: 1
  OK: 3
  BAD: 2
  BAD: 4
  </code></pre>
  
  <p>Here's the most straightforward way I could think of:</p>
  
  <pre class="lang-py prettyprint-override"><code>if True:
      for i in a:
          for k,v in b.items():
              if i in v:
                  do_stuff(i, k)
                  break
  else:
      for k,v in b.items():
          for i in v:
              do_stuff(k, i)
  </code></pre>
  
  <p>On the surface, it seems like those two are unrelated but I can't help but think there must be a better way that I'm missing here...</p>
  
  <p>Thanks in advance!</p>