0

我想使用字典将字符串更改为整数,但我很确定如何。例如:

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
4

1 回答 1

0

您遍历每个元素:

encrypted = ''

for character in secret:
    encrypted += dictionary[character]

或更简洁地说:

encrypted = map(dictionary.get, secret)
于 2013-07-06T01:44:50.490 回答