Skip to content

Instantly share code, notes, and snippets.

@hackjoy
Created February 10, 2013 14:06
Show Gist options
  • Save hackjoy/4749678 to your computer and use it in GitHub Desktop.
Save hackjoy/4749678 to your computer and use it in GitHub Desktop.
Split a string based on pre defined split characters
def split_string(source,splitlist):
output = []
atsplit = True
for char in source:
if char in splitlist:
atsplit = True
else:
if atsplit:
output.append(char)
atsplit = False
else:
output[-1] = output[-1] + char
return output
out = split_string("This is a test-of the,string separation-code!"," ,!-")
print out
#>>> ['This', 'is', 'a', 'test', 'of', 'the', 'string', 'separation', 'code']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment