code: def filter_paths(d, paths, list_of_dicts=False, deepcopy=True):
      
      list_of_dicts = '__list__' if list_of_dicts else None
  
      all_keys = [x for y in paths if isinstance(y, tuple) for x in y]
      all_keys += [x for x in paths if not isinstance(x, tuple)]
      # faster to filter first I think
      new_d = filter_keys(d, all_keys, list_of_dicts=list_of_dicts)
      new_d = flatten(d, list_of_dicts=list_of_dicts)
      for key in list(new_d.keys()):
          if not any([
                  set(key).issuperset(path if isinstance(path, tuple) else[path])
                  for path in paths]):
              new_d.pop(key)
      return unflatten(new_d, list_of_dicts=list_of_dicts, deepcopy=deepcopy)
docs: filter dict by certain paths containing key sets
  
      Parameters
      ----------
      d : dict
      paths : list[str] or list[tuple]
      list_of_dicts: bool
          treat list of dicts as additional branches
      deepcopy: bool
          deepcopy values
  
      Examples
      --------
  
      >>> from pprint import pprint
      >>> d = {'a':{'b':1,'c':{'d':2}},'e':{'c':3}}
      >>> filter_paths(d,[('c','d')])
      {'a': {'c': {'d': 2}}}
  
      >>> d2 = {'a':[{'b':1,'c':3},{'b':1,'c':2}]}
      >>> pprint(filter_paths(d2,["b"],list_of_dicts=False))
      {}
  
      >>> pprint(filter_paths(d2,["c"],list_of_dicts=True))
      {'a': [{'c': 3}, {'c': 2}]}