- 1

"Secret message" problem.

My code: https://code.sololearn.com/cuOYOs3Bn1gX/?ref=app It is, surprisingly, not obeying my "reverse_alphabet" dictionary. What is the problem with it?

6th Jan 2020, 1:05 AM
Gabriel Pedroza
Gabriel Pedroza - avatar
2 odpowiedzi
+ 6
You are performing replace for every letter, but everytime for the full word. This means, that you might switch letters back and forth a few times. I'd choose this method: w = '' for letter in new_message: w += reverse_alphabet[letter] print(w)
6th Jan 2020, 1:13 AM
HonFu
HonFu - avatar
+ 1
HonFu, you are absolutely right! I am really grateful for your teaching ("don't be afraid to build a string form scratch")!
6th Jan 2020, 1:47 AM
Gabriel Pedroza
Gabriel Pedroza - avatar