Skip to content

Instantly share code, notes, and snippets.

@shaneshifflett
Created November 21, 2012 07:19
Show Gist options
  • Save shaneshifflett/4123556 to your computer and use it in GitHub Desktop.
Save shaneshifflett/4123556 to your computer and use it in GitHub Desktop.
Standardize a string
def key_str(term):
'''
remove as much from the string as possible while
preserving its meaning
'''
term = term.strip()
obv = term.split(' ')
obv = map(lambda x: x.strip(), obv)
term = ' '.join(obv)
term = term.lower()
term = rm_punctuation(term)
return term
def rm_punctuation(term):
#term = term.translate(string.maketrans("",""), string.punctuation)
exclude = set(string.punctuation)
return ''.join(ch for ch in term if ch not in exclude)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment