def _Q(filter_, thing):
 T = type(thing)
 if isinstance({}, T):
  for (k, v) in compat.iteritems(thing):
   if (filter_ == k):
    if isinstance(v, type([])):
     (yield iter(v))
    else:
     (yield v)
   if (type(v) in (type({}), type([]))):
    (yield Q(filter_, v))
 elif isinstance([], T):
  for k in thing:
   (yield Q(filter_, k))
 else:
  pass

def _Q ( filter_ , thing ) : T = type ( thing ) if isinstance ( { } , T ) : for ( k , v ) in compat . iteritems ( thing ) : if ( filter_ == k ) : if isinstance ( v , type ( [ ] ) ) : ( yield iter ( v ) ) else : ( yield v ) if ( type ( v ) in ( type ( { } ) , type ( [ ] ) ) ) : ( yield Q ( filter_ , v ) ) elif isinstance ( [ ] , T ) : for k in thing : ( yield Q ( filter_ , k ) ) else : pass
underlying machinery for q function recursion .