code: def _clean_empty(d):
      
      if not isinstance(d, (dict, list)):
          return d
      if isinstance(d, list):
          return [v for v in (_clean_empty(v) for v in d) if v is not None]
      return {
          k: v for k, v in
          ((k, _clean_empty(v)) for k, v in d.items())
          if v is not None
      }
docs: Remove None values from a dict.