Skip to content

Instantly share code, notes, and snippets.

@luismond
Created March 13, 2019 19:51
Show Gist options
  • Select an option

  • Save luismond/74ec1ddaf341ccbe6808da28485cd68f to your computer and use it in GitHub Desktop.

Select an option

Save luismond/74ec1ddaf341ccbe6808da28485cd68f to your computer and use it in GitHub Desktop.
Strip punctuation function
def strip_punct(line):
line = str(line)
charset = set()
for ch in line:
charset.update(ch)
punct = [ch for ch in charset if not ch.isalpha()]
if ' ' in punct:
punct.remove(' ')
for ch in punct:
line = line.replace(ch, ' ').lower()
line = line.replace(' ', ' ').lower()
return line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment