Skip to content

Instantly share code, notes, and snippets.

@maksymx
Last active August 29, 2015 14:04
Show Gist options
  • Save maksymx/11383ba09e95089bf330 to your computer and use it in GitHub Desktop.
Save maksymx/11383ba09e95089bf330 to your computer and use it in GitHub Desktop.
Remove specific characters from a string in python
# 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