Created
November 27, 2019 18:50
-
-
Save jag-k/52c00e5c04986089241b28e8f20cb062 to your computer and use it in GitHub Desktop.
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
def split_string(string): | |
buf = [] | |
result = [] | |
buffer = "" | |
for i in string: | |
if i in "()[]{}\"'": | |
continue | |
if i in ".?!\n": | |
result.append(buf + [buffer]) | |
buffer = "" | |
buf = [] | |
elif i.isalpha(): | |
buffer += i | |
elif i.isspace(): | |
buf.append(buffer) | |
buffer = "" | |
else: | |
buf.append(buffer) | |
buffer = "" | |
buf.append(i) | |
if buffer: | |
result[-1].append(buffer) | |
return [[j for j in i if j] for i in result] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment