def consecutive(l, fn):
 it = iter(l)
 ll = []
 try:
  while True:
   x = it.next()
   if fn(x):
    ll.append(x)
   else:
    if ll:
     (yield ll)
     ll = []
    (yield [x])
 except StopIteration:
  if ll:
   (yield ll)

def consecutive ( l , fn ) : it = iter ( l ) ll = [ ] try : while True : x = it . next ( ) if fn ( x ) : ll . append ( x ) else : if ll : ( yield ll ) ll = [ ] ( yield [ x ] ) except StopIteration : if ll : ( yield ll )
yield consecutive items from l that fn returns true for them .