title: How to filter by keys through a nested dictionary in a pythonic way
body: <p>Try to filter a nested dictionary. My solution is clunky, was hoping to see if there is a better method something using comprehensions. Only interested in the dictionary and lists for this example.</p>
  
  <p>_dict_key_filter() will filter the keys of a nested dictionary or a list of nested dictionaries. Anything not in the obj_filter will be ignored on all nested levels.</p>
  
  <p>obj : can be a dictionary or a list of dictionaries.</p>
  
  <p>obj_filter: has to be a list of filter values</p>
  
  <pre><code>def _dict_key_filter(self, obj, obj_filter):
      if isinstance(obj, dict):
          retdict = {}
          for key, value in obj.iteritems():
              if key in obj_filter:
                  retdict[key] = copy.deepcopy(value)
              elif isinstance(value, (dict, list)):
                  child = self._dict_key_filter(value, obj_filter)
                  if child:
                      retdict[key] = child
          return retdict if retdict else None
      elif isinstance(obj, list):
          retlist = []
          for value in list:
              child = self._dict_key_filter(value, obj_filter)
              if child:
                  retlist.append(child)
          return retlist if retlist else None
      else:
          return None
  
  Example#
  dict1 = {'test1': {'test2':[1,2]}, 'test3': [{'test6': 2}, 
           {'test8': {'test9': 23}}], 'test4':{'test5': 5}}
  
  filter = ['test5' , 'test9']
  
  return = _dict_key_filter(dict1, filter)
  
  return value would be {'test3': [{'test8': {'test9': 23}}], 'test4': {'test5': 5}}
  </code></pre>