如何将 iv'e 已经找到的新键放入新字符串中?



我想把我找到的新键并打印一个创建逻辑句子的新字符串:

words = {'h': 'e', 'k': 't', 'm': 'o', 'u': 'r', 'e': 'h', 't': 'k', 'o': 'm', 'r': 'u'}
def text(str):
print('the original text', str)

original_text = 'puackich, hvhnkrally oaths phufhck. all ymr nhhd is pykemn. j.u.u.u kmltin.mmps iks nmk eio; ---> hkmu'

print(original_text)
if x == original_text:
print(True)
else:

我该怎么办?

如果要根据字典words解码字符串,可以使用下一个示例str.join+dict.get。例如:

words = {
"h": "e",
"k": "t",
"m": "o",
"u": "r",
"e": "h",
"t": "k",
"o": "m",
"r": "u",
}

def text(s):
print("the original text", s)
print("".join(words.get(ch, ch) for ch in s))

original_text = "puackich, hvhnkrally oaths phufhck. all ymr nhhd is pykemn. j.u.u.u kmltin.mmps iks nmk eio; ---> hkmu"
text(original_text)

打印:

the original text puackich, hvhnkrally oaths phufhck. all ymr nhhd is pykemn. j.u.u.u kmltin.mmps iks nmk eio; ---> hkmu
practice, eventually makes perfect. all you need is python. j.r.r.r tolkin.oops its not him; ---> etor

相关内容

  • 没有找到相关文章