How to clean a dictionary where the values are equal to a variable : <p>I have a dictionary composed of multiple key. Is has been created by a loop so the keys generated at the beginning don't have values but, I fill them later.
Sometimes, a key is not filled so I want to remove it from the dictionary </p>

<p>The dictionary look like:</p>

<pre><code>{'a' : [1,2,3,4] , 'b' : [5,6,7,8] ,'c': [] ,'d': [9,10,11]}
</code></pre>

<p>I may have multiple values that look like 'c'
i have tried the try/except but still get the "dictionary changed size during iteration"</p>

<pre><code>d= {'a' : [1,2,3,4] , 'b' : [5,6,7,8] ,'c': [] ,'d': [9,10,11]}
dic_key = d.keys()
for key in dic_key:
         try:
             if len(d[key]) == 0:
                    del d[key]
         except:
             pass
</code></pre>

<p>"dictionary changed size during iteration"</p>
