不能想出如何用数字替换字母。例如,用python中的数字替换单词中的多个字母?
可以说
'a' , 'b' and 'c' should be replaced by "2".
'd' , 'e' and 'n' should be replaced by "5".
'g' , 'h' and 'i' should be replaced by "7".
我想替换的字符串是again
。我想要得到的输出是27275
。 这些数字的结果应该是字符串。
到目前为止我有:
def lett_to_num(word):
text = str(word)
abc = "a" or "b" or "c"
aef = "d" or "e" or "n"
ghi = "g" or "h" or "i"
if abc in text:
print "2"
elif aef in text:
print "5"
elif ghi in text:
print "7"
^我知道上面是错误的^
我应该写什么功能?从串
你认为你应该写什么函数?显示一点点努力,然后我们会更可能帮助你 – hd1
为什么'n'是'5'? – jfs
这只是一个例子。所以我可以再拼出'再'一词。 – user3463010