def rec_test(sequence, test_func):
 for x in sequence:
  if isinstance(x, (list, tuple)):
   for y in rec_test(x, test_func):
    (yield y)
  else:
   (yield test_func(x))

def rec_test ( sequence , test_func ) : for x in sequence : if isinstance ( x , ( list , tuple ) ) : for y in rec_test ( x , test_func ) : ( yield y ) else : ( yield test_func ( x ) )
tests test_func on all items of sequence and items of included sub-iterables .