def split_ranges(mask):
 ranges = [(0, len(mask))]
 for (pos, val) in enumerate(mask):
  if (not val):
   r = ranges.pop()
   if (pos > r[0]):
    (yield (r[0], pos))
   if ((pos + 1) < len(mask)):
    ranges.append(((pos + 1), len(mask)))
 if ranges:
  (yield ranges[(-1)])

def split_ranges ( mask ) : ranges = [ ( 0 , len ( mask ) ) ] for ( pos , val ) in enumerate ( mask ) : if ( not val ) : r = ranges . pop ( ) if ( pos > r [ 0 ] ) : ( yield ( r [ 0 ] , pos ) ) if ( ( pos + 1 ) < len ( mask ) ) : ranges . append ( ( ( pos + 1 ) , len ( mask ) ) ) if ranges : ( yield ranges [ ( - 1 ) ] )
generates tuples of ranges which cover all true value in mask .