I'm trying to remove non-values from a nested dictionary. My first effort works fine, but unfortunately keys pointing to now empty dicts still persist.
So if i do:
pass1 = stripper(my_dict)
return stripper(pass1)
This works, but i'm thinking a more elegant nested solution might be possible?
def stripper(self, data):
    if isinstance(data, dict):
        d = ({k: stripper(v) for k, v in data.items()
             if v not in [u'', None]})
        if d:
            return d
    else:
        return data
Edit:
Failing example, dict below returns as {'foo': 'bar', 'bar': None}:
{
    'foo': 'bar',
    'bar': {
        'foo': None,
        'one': None
    }
}
 
     
     
     
    