from string import maketrans
encrypted = "abc" # chars to be translated
decrypted = "efg" # their replacements
trantab = maketrans(originals, encrypted) # make translation table from them
print encrypted_message.translate( trantab ) # Apply method translate() to user input
对于Python 3.x:
encrypted = "abc" # chars to be translated
decrypted = "efg" # their replacements
trantab = str.maketrans(encrypted, decrypted) # make translation table from them
print( encrypted_message.translate( trantab ) ) # Apply method translate() to user input
使用
translate()
方法:对于Python 2.x:
对于Python 3.x:
使用字典,然后将用户的输入映射到字典的
get
方法以检索每个值:相关问题 更多 >
编程相关推荐