code: def grep_split(pattern, text):
      '''Take the lines in *text* and split them each time the pattern
      matches a line.
  
      '''
      lines = text.splitlines()
      indices = [i for i, line in enumerate(lines)
                 if re.search(pattern, line)]
      
      return ['\n'.join(part) for part in partition(lines, indices)f grep_split(pattern, text):
      '''Take the lines in *text* and split them each time the pattern
      matches a line.
  
      '''
      lines = text.splitlines()
      indices = [i for i, line in enumerate(lines)
                 if re.search(pattern, line)]
      
      return ['\n'.join(part) for part in partition(lines, indices)]
docs: Take the lines in *text* and split them each time the pattern
      matches a line.