Skip to content

Instantly share code, notes, and snippets.

@dragneelfps
Created December 20, 2017 10:23
Show Gist options
  • Save dragneelfps/eeb32b0c5c094252211c1fad3d8275cd to your computer and use it in GitHub Desktop.
Save dragneelfps/eeb32b0c5c094252211c1fad3d8275cd to your computer and use it in GitHub Desktop.
Replace the characters in the string
#Characters to replace
escape_table = {
"&" : " ",
"#" : "1"
}
#Initial string
text = "asd&#"
#Final string
new = "".join(escape_table.get(c,c) for c in text)
print(new)
#Output: asd 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment