Last active
April 29, 2020 09:57
-
-
Save jonathanagustin/fc08a48f535b1d856a33b229c39670b0 to your computer and use it in GitHub Desktop.
Clean way of removing 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
| import string | |
| # make table for translate() to remove punctuation | |
| table = str.maketrans('', '', string.punctuation) | |
| my_string = "!!!asdf" | |
| new_string = my_string.translate(table) | |
| print(new_string) | |
| # prints asdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment