Last active
August 29, 2015 14:04
-
-
Save maksymx/11383ba09e95089bf330 to your computer and use it in GitHub Desktop.
Remove specific characters from a string in python
This file contains 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
# You can instead use str.translate: | |
line = line.translate(None, '!@#$') | |
# — which only works on Python 2.6 and newer Python 2.x versions * — | |
# or regular expression replacement with re.sub | |
import re | |
line = re.sub('[!@#$]', '', line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment