Do not back down, harvest.
def starttoend(it): for line in it: if 'START' in line: yield line break for line in it: yield line if 'END' in line: break l = ['asd', 'zxc', 'START123', '456789', 'qwertyEND', 'fgh', 'cvb'] i = iter(l) for line in starttoend(i): print line
Just use an iterator if you need more sequences.
source share