-
-
Save mrtazz/879213 to your computer and use it in GitHub Desktop.
This file contains 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 tsplit(string, delimiters): | |
"""Behaves str.split but supports multiple delimiters.""" | |
delimiters = tuple(delimiters) | |
stack = [""] # stack to return | |
for i in xrange(len(string)): | |
if string[i] in delimiters: | |
stack.append("") | |
else: | |
stack[-1] += string[i] | |
return stack |
This file contains 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
>>> s = 'thing1,thing2/thing3-thing4' | |
>>> tsplit(s, (',', '/', '-')) | |
['thing1', 'thing2', 'thing3', 'thing4'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment