Skip to content

Instantly share code, notes, and snippets.

@ashwin
Created May 4, 2012 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashwin/2595073 to your computer and use it in GitHub Desktop.
Save ashwin/2595073 to your computer and use it in GitHub Desktop.
Character translation in Python
# Replace 'a' with '1', 'b' with '2' and 'c' with '3'
table = bytes.maketrans( b"abc", b"123" )
s = "abracadabra"
s2 = s.translate( table )
print( s2 ) # 12r131d12r1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment