Skip to content

Instantly share code, notes, and snippets.

@zthomae
Created August 19, 2012 01:23
Show Gist options
  • Select an option

  • Save zthomae/3390778 to your computer and use it in GitHub Desktop.

Select an option

Save zthomae/3390778 to your computer and use it in GitHub Desktop.
Python snippets
## SPLIT AROUND SPACE ##
import string
# All forms of whitespace except the space
whitespace = string.whitespace[:-1]
# Split a string around its whitespace, with words and whitespace being entries in a list
def split_around_space(string):
new = []
current = ""
for i in string:
if i.isspace():
new.append(current)
current = ""
if i in whitespace: # Included for demonstration: Only include "important" whitespace (from above)
new.append(i)
else:
current += i
new.append(current)
return new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment