Skip to content

Instantly share code, notes, and snippets.

@kgriffs
Created June 29, 2020 22:29
Show Gist options
  • Save kgriffs/3a80dfd2e6741f93482ca5933d3555ce to your computer and use it in GitHub Desktop.
Save kgriffs/3a80dfd2e6741f93482ca5933d3555ce to your computer and use it in GitHub Desktop.
isplit -- Iterative split for Python strings.
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