def Q(filter_, thing):
 if isinstance(filter_, type([])):
  return flatten(*[_Q(x, thing) for x in filter_])
 elif isinstance(filter_, type({})):
  d = dict.fromkeys(list(filter_.keys()))
  for k in d:
   d[k] = Q(k, thing)
  return d
 elif (' ' in filter_):
  parts = filter_.strip().split()
  r = None
  for p in parts:
   r = Ql(p, thing)
   thing = r
  return r
 else:
  return flatten(_Q(filter_, thing))

def Q ( filter_ , thing ) : if isinstance ( filter_ , type ( [ ] ) ) : return flatten ( * [ _Q ( x , thing ) for x in filter_ ] ) elif isinstance ( filter_ , type ( { } ) ) : d = dict . fromkeys ( list ( filter_ . keys ( ) ) ) for k in d : d [ k ] = Q ( k , thing ) return d elif ( ' ' in filter_ ) : parts = filter_ . strip ( ) . split ( ) r = None for p in parts : r = Ql ( p , thing ) thing = r return r else : return flatten ( _Q ( filter_ , thing ) )
type: - list: a flattened list of all searches - dict: dict with vals each of which is that search notes: [1] parent thing .