Created
December 8, 2017 17:15
-
-
Save youngsoul/34d4ded8d4edb82fdfb8f9a91ade2c0d to your computer and use it in GitHub Desktop.
Python 3 way to use translate to remove punctuation from a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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