Parse nested dictionary python and remove complete hierarchy if all its leaf node is empty
<pre><code>c_dict = {'a': {'b': {'c': [1], 'd': [{'e': {'val': [1]}}, {'e': {'val': []}}]}}}
def clean_dict(d):
    for key, val in d.items():
        if isinstance(val, list):  # CAT -&gt; This "if" handles list of dicts
            for i in val:
                if isinstance(i, dict):
                    val = clean_dict(i)
        if isinstance(val, dict):
            val = clean_dict(val)
        if val is None or val == {} or val == []:
            del d[key]
    return d
print clean_dict(c_dict)
</code></pre>

<p>The output is:<br></p>

<pre><code>{'a': {'b': {'c': [1]}}}
</code></pre>

<p>But the expected output is:</p>

<pre><code>{'a': {'b': {'c': [1], 'd':[{'e':{'val':[1]}}]}}}
</code></pre>

<p>As inside the list, there is a dict whose leaf node is not empty.<br>
Please let me know what is missing here.</p>