Split on separator but keep the separator, in Python

Posted on Fri 23 December 2011 in Coding • Tagged with reduce, split, string, Python

I have a function that reads from a file using file’s iterator capability, i.e. (simplified version, in reality there’s going on more within the generator):

def readfile(f):
    using open(f) as fd:
        for line in fd:
            yield line

If the file contains something like a\nb …


Continue reading