我想使用字典将字符串更改为整数但我注意到如何确定。例如:
secret = raw_input(enter the secret code)
list(code)
dictionary = {a:1, b:2, c:3,d:4,e:5,f:6,g:7,h:8,i:9,#etc.}
encryptedSecret = dictionary(code)
return encryptedSecret
答案 0 :(得分:0)
迭代每个元素:
encrypted = ''
for character in secret:
encrypted += dictionary[character]
或者更简洁:
encrypted = map(dictionary.get, secret)