Fate of itertools.dropwhile() and itertools.takewhile()

Raymond Hettinger python at rcn.com
Sun Dec 30 20:25:33 EST 2007


FWIW, here is an generator version written without the state flag:

    def iter_block(lines, start_marker, end_marker):
        lines = iter(lines)
        for line in lines:
            if line.startswith(start_marker):
                yield line
                break
        for line in lines:
            if line.startswith(end_marker):
                return
            yield line

Raymond



More information about the Python-list mailing list