Skip to content

Instantly share code, notes, and snippets.

@hackjoy
Last active December 11, 2015 09:58
Show Gist options
  • Select an option

  • Save hackjoy/4583096 to your computer and use it in GitHub Desktop.

Select an option

Save hackjoy/4583096 to your computer and use it in GitHub Desktop.
Split a string based on predefined characters
def split_string(string, split_characters):
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 # add char to last word
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment