Tiny Updates
« Functional Lagrange Interpolation | Main | DMOZ Scraper »
Monday
May022011

Python super_split()

I recently needed some code that splits python strings based on multiple delimitors, so I wrote a quick function to do so. I figured it’s generally useful so I’m posting it here.

def super_split(string, delim):
    segment = ''
    for c in string:
        if c in delim:
            yield segment
            segment = ''
        else:
            segment += c
    yield segment

PrintView Printer Friendly Version

EmailEmail Article to Friend