title: Recursively remove None value or None key from nested dict
body: <p><strong>Question:</strong></p>
  <p>How can I iterate over a dictionary and remove <code>None</code> keys or values from it?</p>
  <p>Here is what I've tried:</p>
  <p><strong>Code:</strong></p>
  <pre class="lang-py prettyprint-override"><code>import copy
  
  
  def _ignore(data):
      copied_data = copy.deepcopy(data)
  
      print('-------------------------')
      print(f'copied_data: {copied_data}')
      print('-------------------------')
  
      if isinstance(copied_data, list):
          print(f'item is instance of list: {copied_data}')
  
          for idx, item in enumerate(data):
              if isinstance(item, list):
                  return _ignore(item)
  
              elif isinstance(item, dict):
                  return _ignore(item)
  
              elif item is None:
                  del copied_data[idx]
  
      elif isinstance(copied_data, dict):
          print(f'item is instance of dict: {copied_data}')
  
          for key, item in data.items():
              if isinstance(item, list):
                  return _ignore(item)
  
              elif isinstance(item, dict):
                  return _ignore(item)
  
              elif item is None:
                  del copied_data[key]
  
      return copied_data
  
  
  if __name__ == '__main__':
      data = {'key1': None, 'key2': {'k1': None, 'k2': 2}, 'key3': [None, 1, 2, 3, 4]}
  
      print(f'output: {_ignore(data=data)}')
  </code></pre>
  <p><strong>Input:</strong></p>
  <pre class="lang-py prettyprint-override"><code>{'key1': None, 'key2': {'k1': None, 'k2': 2}, 'key3': [None, 1, 2, 3, 4]}
  </code></pre>
  <p><strong>Output:</strong></p>
  <pre class="lang-py prettyprint-override"><code>-------------------------
  copied_data: {'key1': None, 'key2': {'k1': None, 'k2': 2}, 'key3': [None, 1, 2, 3, 4]}
  -------------------------
  item is instance of dict: {'key1': None, 'key2': {'k1': None, 'k2': 2}, 'key3': [None, 1, 2, 3, 4]}
  -------------------------
  copied_data: {'k1': None, 'k2': 2}
  -------------------------
  item is instance of dict: {'k1': None, 'k2': 2}
  output: {'k2': 2}
  </code></pre>
  <blockquote>
  <p><strong>Keep in mind</strong> that the code also should remove <code>None</code> values in a nested <code>list</code> or nested <code>dict</code> and we can't remove an element from <code>dict</code> while we are iterating over it.</p>
  </blockquote>
  <p><strong>Update:</strong>
  The code should support nested <code>dict</code> or <code>list</code></p>
  <p><strong>Here is another input sample:</strong></p>
  <pre class="lang-py prettyprint-override"><code>{'key1': None, None:1 ,'key2': {'k1': {'k3': [None, 1, 23], 'k4': None}, 'k2': 2},
          'key3': [{'key1': None, 'key2': [None, 1, 2, 3], 'key3': {'k1': 1}}, 1, 2, 3, 4]} 
  </code></pre>
  <p>Thanks.</p>