title: Python dictionary iteration
body: <p>I have a dictionary <code>dict2</code> which I want to iter through and remove all entries that contain certain ID numbers in <code>idlist</code>.  <code>dict2[x]</code> is a list of lists (see example dict2 below).  This is the code I have written so far, however it does not remove all instances of the IDs (<code>entry[1]</code>) that are in the <code>idlist</code>.  Any help?</p>
  
  <pre><code>dict2 = {G1:[[A, '123456', C, D], [A, '654321', C, D], [A, '456123', C, D], [A, '321654', C, D]]}
  
  idlist = ['123456','456123','321654']
  for x in dict2.keys():
      for entry in dict2[x]:
          if entry[1] in idlist:
              dict2[x].remove(entry)
          if dict2[x] == []:
              del dict2[x]
  </code></pre>
  
  <p><code>dict2</code> should end up looking like this :</p>
  
  <pre><code>dict2 = {G1:[[A, '654321', C, D]]}
  </code></pre>