Skip to content

Instantly share code, notes, and snippets.

@youngsoul
Created December 8, 2017 17:15
Show Gist options
  • Save youngsoul/34d4ded8d4edb82fdfb8f9a91ade2c0d to your computer and use it in GitHub Desktop.
Save youngsoul/34d4ded8d4edb82fdfb8f9a91ade2c0d to your computer and use it in GitHub Desktop.
Python 3 way to use translate to remove punctuation from a string
# https://stackoverflow.com/questions/265960/best-way-to-strip-punctuation-from-a-string-in-python
import string
def remove_punctuation(x):
table = str.maketrans({key: None for key in string.punctuation})
return x.translate(table)
# mydoc = Appearance: Deep Amber with medium bubbles and an off-white head settles quick with even lacing. Head upon initial pour rose to about one finger's length.
# print(remove_punctuation(mydoc)
# Appearance Deep Amber with medium bubbles and an offwhite head settles quick with even lacing Head upon initial pour rose to about one fingers length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment