Created
June 29, 2020 22:29
-
-
Save kgriffs/3a80dfd2e6741f93482ca5933d3555ce to your computer and use it in GitHub Desktop.
isplit -- Iterative split for Python strings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
# Based on: https://stackoverflow.com/a/59071238/21784 | |
def isplit(s, sep='\n'): | |
sep = re.escape(sep) | |
start = 0 | |
for m in re.finditer(sep, s): | |
begin, end = m.span() | |
if begin != start: | |
yield s[start:begin] | |
start = end | |
remainder = s[start:] | |
if remainder: | |
yield remainder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment