def del_none(d):
 for (key, value) in d.items():
  if (value is None):
   del d[key]
  elif isinstance(value, dict):
   del_none(value)
  elif isinstance(value, list):
   for v in value:
    if isinstance(v, dict):
     del_none(v)
     if (not v):
      d[key] = []
 return d

def del_none ( d ) : for ( key , value ) in d . items ( ) : if ( value is None ) : del d [ key ] elif isinstance ( value , dict ) : del_none ( value ) elif isinstance ( value , list ) : for v in value : if isinstance ( v , dict ) : del_none ( v ) if ( not v ) : d [ key ] = [ ] return d
delete keys with the value none in a dictionary .