How to put the new keys that iv'e already found in the new string?

Viewed 37

i want to put the new keys that i found and printing a new string that create a logical sentence:

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:


what should i do?

1 Answers

If you want to decode the string according the dictionary words, you can use next example str.join + dict.get. For example:

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)

Prints:

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
Related